views:

402

answers:

1

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  A: 

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.

Eric
I get the same error message.
Masi
What's the results of this query when run directly against MySQL: `select user_id from users where email = '[email protected]'`
Eric
@Eric: It gives 1.
Masi
What if you replace the `pg_execute` with `pg_query()`? Do you get all `user_id`s? If not, you may not be connecting to the database.
Eric
@Eric: I get exactly the same output in connecting to database with pg_query. I can get all `user_id`'s.
Masi