Some PDO drivers return a larger array. For example, the SQL Server driver returns 5 values.
For example:
<?php
$numRows = $db->exec("DELETE FROM [TableName] WHERE ID between 6 and 17");
print_r($db->errorInfo());
?>
Result:
Array
(
[0] => 00000
[1] => 0
[2] => (null) [0] (severity 0) []
[3] => 0
[4] => 0
)
PDO::errorInfo
(PHP 5 >= 5.1.0, PECL pdo:0.1-1.0.3)
PDO::errorInfo — データベースハンドラにおける直近の操作に関連する拡張エラー情報を取得する
説明
array PDO::errorInfo
( void
)
返り値
PDO::errorInfo() は、 このデータベースハンドラによって実行された直近の操作に関するエラー情報を 配列として返します。この配列は次のフィールドを含みます。
| 要素 | 情報 |
|---|---|
| 0 | SQLSTATE エラーコード (これは、ANSI SQL 標準で定義された英数 5 文字の ID) |
| 1 | ドライバ固有のエラーコード |
| 2 | ドライバ固有のエラーメッセージ |
PDO::errorInfo() はデータベースハンドラに 直接行った操作に対するエラーコードのみを取得します。 もし PDO::prepare() や PDO::query() を通して PDOStatement オブジェクトを生成し、 文でエラーが発生した場合、PDO::errorInfo() はそのエラーを反映しません。 特定の文ハンドラに対して実行された操作についてのエラーコードを返すには PDOStatement::errorInfo() をコールしなければなりません。
例
例1 DB2 データベースに対する PDO_ODBC 接続の errorInfo() フィールドを表示する
<?php
/* エラーを発生させる -- 無効な SQL シンタックス */
$stmt = $dbh->prepare('bogus sql');
if (!$stmt) {
echo "\nPDO::errorInfo():\n";
print_r($dbh->errorInfo());
}
?>
上の例の出力は以下となります。
PDO::errorInfo(): Array ( [0] => HY000 [1] => 1 [2] => near "bogus": syntax error )
PDO::errorInfo
mazen at mindcraftinc dot com
23-Sep-2008 11:43
23-Sep-2008 11:43
quickshiftin at gmail dot com
02-Jun-2007 08:29
02-Jun-2007 08:29
here are the error codes for sqlite, straight from their site:
The error codes for SQLite version 3 are unchanged from version 2. They are as follows:
#define SQLITE_OK 0 /* Successful result */
#define SQLITE_ERROR 1 /* SQL error or missing database */
#define SQLITE_INTERNAL 2 /* An internal logic error in SQLite */
#define SQLITE_PERM 3 /* Access permission denied */
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
#define SQLITE_BUSY 5 /* The database file is locked */
#define SQLITE_LOCKED 6 /* A table in the database is locked */
#define SQLITE_NOMEM 7 /* A malloc() failed */
#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite_interrupt() */
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
#define SQLITE_NOTFOUND 12 /* (Internal Only) Table or record not found */
#define SQLITE_FULL 13 /* Insertion failed because database is full */
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
#define SQLITE_EMPTY 16 /* (Internal Only) Database table is empty */
#define SQLITE_SCHEMA 17 /* The database schema changed */
#define SQLITE_TOOBIG 18 /* Too much data for one row of a table */
#define SQLITE_CONSTRAINT 19 /* Abort due to contraint violation */
#define SQLITE_MISMATCH 20 /* Data type mismatch */
#define SQLITE_MISUSE 21 /* Library used incorrectly */
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
#define SQLITE_AUTH 23 /* Authorization denied */
#define SQLITE_ROW 100 /* sqlite_step() has another row ready */
#define SQLITE_DONE 101 /* sqlite_step() has finished executing */
quickshiftin at gmail dot com
20-Mar-2007 09:43
20-Mar-2007 09:43
here is a reference to the ansi error codes
there are several others;
a link to the official spec from ansi would be nice
(have to rebuild this link because its too long to post w/o breaking it up)
http://download-east.oracle.com/docs/
cd/B14117_01/appdev.101/a87540/ch2.htm
~quickshiftin`
Travis Pulley (travis at pulley dot org)
22-Aug-2006 06:29
22-Aug-2006 06:29
The example code is incorrect. The line that reads:
$err = $dbh->prepare('SELECT skull FROM bones');
Will set the value of $err to be boolean FALSE.
So, to get a useful error dump change this line:
print_r($err->errorInfo());
to:
print_r($dbh->errorInfo());
