array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), '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' => 'ja', '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
PgSql\Connection クラスのインスタンス。
connection
が null
, の場合、デフォルトの接続を使います。
デフォルトの接続とは、pg_connect() または pg_pconnect() によって確立された直近の接続です。
PHP 8.1.0 以降では、デフォルトの接続を使うことは推奨されなくなりました。
指定した connection
の直近のエラーメッセージを
含む文字列を返します。
バージョン | 説明 |
---|---|
8.1.0 |
connection は、PgSql\Connection クラスのインスタンスを期待するようになりました。
これより前のバージョンでは、リソース を期待していました。
|
8.0.0 |
connection は、nullable になりました。
|
例1 pg_last_error() の例
<?php
$dbconn = pg_connect("dbname=publisher") or die("接続できませんでした");
// 失敗するクエリ
$res = pg_query($dbconn, "select * from doesnotexist");
echo pg_last_error($dbconn);
?>