Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

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

share|improve this answer
    
that's it. Thanks. So it was PostgreSQL (well my syntax), not PHP. –  Kingsley Oct 9 '12 at 8:36
add comment

The answer is simple - just remove brackets from SELECT statement, like this:

$query = "SELECT id,serial,tag FROM devices ORDER BY tag ASC";

otherwise it is a string in output.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.