How can I resolve the "Resource ID #8" error message in PostgreSQL/PHP?

10.7k views Asked by At

How can you solve the Resource ID #8 -error message in the following code?

The error apparently means that I have a bug in my SQL statement. However, I cannot see it.

 $result = pg_prepare($dbconn, "query1", "SELECT user_id FROM users 
     WHERE email = $1;");
 $result = pg_execute($dbconn, "query1", array("[email protected]"));
 // to read the value

 while ($row = pg_fetch_row($result)) {
     $user_id = $row[0];
 }

I get the error message when I try to echo $result.

1

There are 1 answers

3
Eric On BEST ANSWER

Don't echo $result -- it's a record set, not an actual value to be echoed. You should be able to echo $row[0] within the while loop, though:

while ($row = pg_fetch_row($result)) {
     $user_id = $row[0];
     echo $user_id . '<br/>';
 }

There's nothing wrong with the code that you posted, by the way--the syntax is fine.