capturing errors
Jaime Casanova <[email protected]> Fri, 29 Jan 2010 11:06:03 -0500
| Newsgroups | gmane.comp.db.postgresql.php |
|---|---|
| Message-ID | <[email protected]> |
Hi, I'm trying to capture the error from php to show an informative message to the user but i haven't managed to get it... i'm using pg_result_error_field() but when i print it i get nothing, is there something i have to configure or what i'm doing bad. attached a little php script for testing and here is the schema the script is using (obviously the error i'm trying to catch here is unique violation) """ create table t1_fk1(col1 integer primary key); insert into t1_fk1 values(1); """ -- Atentamente, Jaime Casanova Soporte y capacitación de PostgreSQL AsesorÃa y desarrollo de sistemas Guayaquil - Ecuador Cel. +59387171157 -- Sent via pgsql-php mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-php
prueba.php
(application/x-php, 1.1 KB)
<?php
$dbconn = pg_connect("dbname=pruebas host=localhost user=postgres password=postgres");
$result = @pg_query($dbconn, "insert into t1_fk1 values (1)");
$sql_state = pg_result_error_field($result, PGSQL_DIAG_SQLSTATE);
echo $sql_state;
if (!$result) {
$res1 = pg_get_result($dbconn);
echo pg_result_error_field($res1, PGSQL_DIAG_SEVERITY);
echo pg_result_error_field($res1, PGSQL_DIAG_SQLSTATE);
echo pg_result_error_field($res1, PGSQL_DIAG_MESSAGE_PRIMARY);
echo pg_result_error_field($res1, PGSQL_DIAG_MESSAGE_DETAIL);
echo pg_result_error_field($res1, PGSQL_DIAG_MESSAGE_HINT);
echo pg_result_error_field($res1, PGSQL_DIAG_STATEMENT_POSITION);
echo pg_result_error_field($res1, PGSQL_DIAG_INTERNAL_POSITION);
echo pg_result_error_field($res1, PGSQL_DIAG_INTERNAL_QUERY);
echo pg_result_error_field($res1, PGSQL_DIAG_CONTEXT);
echo pg_result_error_field($res1, PGSQL_DIAG_SOURCE_FILE);
echo pg_result_error_field($res1, PGSQL_DIAG_SOURCE_LINE);
echo pg_result_error_field($res1, PGSQL_DIAG_SOURCE_FUNCTION);
}
?>