pg_last_error
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
pg_last_error — Get the last error message string of a connection
Parameters
connection
-
An PgSql\Connection instance.
When connection is null, the default connection is used.
The default connection is the last connection made by pg_connect()
or pg_pconnect().
WarningAs of PHP 8.1.0, using the default connection is deprecated.
Return Values
A string containing the last error message on the
given connection.
Examples
Example #1 pg_last_error() example
<?php
$dbconn = pg_connect("dbname=publisher") or die("Could not connect");
// Query that fails
$res = pg_query($dbconn, "select * from doesnotexist");
echo pg_last_error($dbconn);
?>