Query return code question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ryan Booz

    Query return code question

    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_f ile"
    lines in there to try and help me figure this out, they are not
    normally there. When the query succeeds, the two "append_error_f ile"
    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_fi le("<--> RESULT BEFORE RETURN: ".$result." <-->");
    append_error_fi le("<--> RESULT LAST ERROR:
    ".pg_last_error ($conn)."<-->");

    if($result == FALSE)
    {
    return pg_last_error($ conn);
    }
    else
    {
    return 0;
    }
Working...