2

I'm trying to handle SQL query errors with pg_query() function.

The code:

    try{
            $result = pg_query($dbconn,"SET application_name = 'testing text'");
            echo $result;
    } catch (Exception $e) {
            echo 'Caught exception: ',  $e->getMessage(), "\n";
    }

Wonder why still I'm getting following warning message from pg_query() line.

Warning: pg_query(): Query failed: ERROR: unrecognized configuration parameter "application_name" in...

I'm try to stop that Warning. Any idea why this is not working?

Yasiru G
  • 6,886
  • 6
  • 23
  • 43
  • 1
    to silence the warning message, prepend @ to pg_query: `$result=@pg_query(...);` – Daniel Vérité Apr 09 '14 at 11:29
  • You might also want to read http://stackoverflow.com/q/22743357/398670 - it's about PDO, but it's relevant to error handling with regular `pg_query` as well. – Craig Ringer Apr 09 '14 at 11:54
  • Thanks Deniel, but @ pg_query removed the error completely. I want to catch that error. But can't catch it with using @ pg_query. – Yasiru G Apr 10 '14 at 02:53
  • Thanks Craig, I can't catch that error when use PDO object. I'm trying to do the same thing with pg_query(). Still no luck. – Yasiru G Apr 10 '14 at 02:57

0 Answers0