PHP.nl

pg_result_error_field

pg_result_error_field

Returns an individual field of an error report

 **pg_result_error_field** PgSql\Result $result int $field_code
returns one of the detailed error message

fields associated with instance. The error field is specified by the . pg_result_error_field``result``field_code

Because and return false if the query fails, you must use and to get the result handle. pg_query``pg_query_params``pg_send_query``pg_get_result

If you need to get additional error information from failed queries,
use and and then parse the result. pg_query``pg_set_error_verbosity``pg_last_error

result``field_code Possible values are: , , , , , , , , , , or . field_code``PGSQL_DIAG_SEVERITY``PGSQL_DIAG_SQLSTATE``PGSQL_DIAG_MESSAGE_PRIMARY``PGSQL_DIAG_MESSAGE_DETAIL``PGSQL_DIAG_MESSAGE_HINT``PGSQL_DIAG_STATEMENT_POSITION``PGSQL_DIAG_INTERNAL_POSITION``PGSQL_DIAG_INTERNAL_QUERY``PGSQL_DIAG_CONTEXT``PGSQL_DIAG_SOURCE_FILE``PGSQL_DIAG_SOURCE_LINE``PGSQL_DIAG_SOURCE_FUNCTION

A containing the contents of the error field, null if the field does not exist or false on failure.string

Voorbeeld: example

<?php
  $dbconn = pg_connect("dbname=publisher") or die("Could not connect");

  if (!pg_connection_busy($dbconn)) {
      pg_send_query($dbconn, "select * from doesnotexist;");
  }
  
  $res1 = pg_get_result($dbconn);
  echo pg_result_error_field($res1, PGSQL_DIAG_SQLSTATE);
?>

pg_result_error