pg_last_error
(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
connectionisnull, 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);
?>参见
- pg_result_error() - 获得跟 result 相关的错误信息
- pg_result_error_field() - Returns an individual field of an error report