Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP5 + PostgreSQL - pg_fetch_row() returning string not array

PHP5 + PostgreSQL (ubuntu 12.04) according to the doco returns an array for pg_fetch_row(). By my test results indicate that it's returning a string, is there some configuration option for this?

$db = openDatabase(<blah>);
$query = "SELECT (id,serial,tag) FROM devices ORDER BY tag ASC";
$result = pg_query($db,$query);
if ($result)
{
    while ($row = pg_fetch_row($result))
        echo "IN: $row[0] - $row[1] - $row[2]";
}

I expect to see

IN: <value> - <value> - <value>

But I get

IN: (<value>,<value>,<value>) - - 

I guess this means pg_fetch_row() is returning a string not an array?!

e.g. the actual run:

IN: (10,7426573,________) - - 
IN: (7,6862,FMUX-TAG) - - 
IN: (9,6914082,L6) - - 

It seems a simple problem, but I can't find an answer. I know I can parse the result, but that's kludgey.

like image 655
Kingsley Avatar asked Jun 11 '26 17:06

Kingsley


1 Answers

Change SELECT (id,serial,tag) into SELECT id,serial,tag and you're done.

like image 93
Frank Heikens Avatar answered Jun 14 '26 06:06

Frank Heikens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!