(PHP 5 >= 5.1.0, PHP 7, PECL pdo >= 0.1.0)
PDO::errorCode — 锟斤拷取锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷一锟轿诧拷锟斤拷锟斤拷氐锟� SQLSTATE
锟斤拷锟斤拷一锟斤拷 SQLSTATE锟斤拷一锟斤拷锟斤拷5锟斤拷锟斤拷母锟斤拷锟斤拷锟斤拷锟斤拷傻锟斤拷锟� ANSI SQL 锟斤拷准锟叫讹拷锟斤拷谋锟绞讹拷锟斤拷锟� 锟斤拷要锟斤拷说锟斤拷一锟斤拷 SQLSTATE 锟斤拷前锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷值锟酵猴拷锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷值锟斤拷伞锟� class value of 01 indicates a warning and is accompanied by a return code of SQL_SUCCESS_WITH_INFO. Class values other than '01', except for the class 'IM', indicate an error. The class 'IM' is specific to warnings and errors that derive from the implementation of PDO (or perhaps ODBC, if you're using the ODBC driver) itself. The subclass value '000' in any class indicates that there is no subclass for that SQLSTATE.
PDO::errorCode() only retrieves error codes for operations performed directly on the database handle. If you create a PDOStatement object through PDO::prepare() or PDO::query() and invoke an error on the statement handle, PDO::errorCode() will not reflect that error. You must call PDOStatement::errorCode() to return the error code for an operation performed on a particular statement handle.
锟斤拷锟斤拷锟斤拷菘锟斤拷锟矫伙拷薪锟斤拷胁锟斤拷锟斤拷锟斤拷蚍祷锟� NULL
锟斤拷
Example #1 取锟斤拷一锟斤拷 SQLSTATE 锟斤拷
<?php
/* 锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷 -- BONES 锟斤拷锟捷憋拷锟斤拷锟斤拷 */
$dbh->exec("INSERT INTO bones(skull) VALUES ('lucy')");
echo "\nPDO::errorCode(): ";
print $dbh->errorCode();
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
PDO::errorCode(): 42S02