By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Query return code question

P: n/a
All...

I'm having problems figuring out what pg_query() really returns when
there is an error. The documentation says it returns "FALSE",
however, when I specifically make a bad query (either bad connection
or bad SQL) and then spit out the value of the result, I get nothing.
I'm trying to test the return so that I know if it worked or not. I
am not a PHP novice, but I really can't figure this out.

Here's an example of what I'm trying to do. I have no idea what to
really test for in the "if" statement. I put the "append_error_file"
lines in there to try and help me figure this out, they are not
normally there. When the query succeeds, the two "append_error_file"
lines return "Resource id #[number]" and nothing respectively. When
the query fails, the they are both blank, yet the test still fails and
this function passes back zero which leads my calling script to
believe that everything is ok. I've tried zero, "0", "" in the if
statement all to no avail.

Any help would be greatly appreciated! Thanks
Ryan Booz

function submit_pquery($query)
{
$conn = db_pconnect();
$result = pg_query($conn, $query);

append_error_file("<--> RESULT BEFORE RETURN: ".$result."<-->");
append_error_file("<--> RESULT LAST ERROR:
".pg_last_error($conn)."<-->");

if($result == FALSE)
{
return pg_last_error($conn);
}
else
{
return 0;
}
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.