array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.pg-last-error.php', 1 => 'pg_last_error', ), 'up' => array ( 0 => 'ref.pgsql.php', 1 => 'PostgreSQL 函数', ), 'prev' => array ( 0 => 'function.pg-insert.php', 1 => 'pg_insert', ), 'next' => array ( 0 => 'function.pg-last-notice.php', 1 => 'pg_last_notice', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/pgsql/functions/pg-last-error.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
pg_last_error — 得到某连接的最后一条错误信息
pg_last_error() 返回指定 connection
的最后一条错误信息。
错误信息可能会被调用的 PostgreSQL(libpq) 内部函数覆盖。如果 PostgreSQL 的内部模块函数产生了多个错误,则可能不能返回适当的错误信息。
使用 pg_result_error()、pg_result_error_field()、pg_result_status() 和 pg_connection_status() 用于更好的错误处理。
注意:
本函数以前的名字为 pg_errormessage()。
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().
As of PHP 8.1.0, using the default connection is deprecated.
string,包含指定 connection
的最后一条错误消息。
版本 | 说明 |
---|---|
8.1.0 |
现在 connection 参数接受 PgSql\Connection
实例,之前接受 resource。
|
8.0.0 |
connection 现在可为 null。
|
示例 #1 pg_last_error() 示例
<?php
$dbconn = pg_connect("dbname=publisher") or die("Could not connect");
// 查询失败
$res = pg_query($dbconn, "select * from doesnotexist");
echo pg_last_error($dbconn);
?>