PDOStatement::errorCode

(no version information, might be only in CVS)

PDOStatement::errorCode --  Fetch the SQLSTATE associated with the last operation on the statement handle

Description

int PDOStatement::errorCode ( void )

警告

這個函數是實驗性質的。這個函數的行為、名稱、和關於此函數的任何其他文件在未來PHP的發行中可能會在不通知的情況下改變。 使用此延伸需自行承擔風險。

Return Values

Returns a SQLSTATE, a five-character alphanumeric identifier defined in the ANSI SQL standard. PDOStatement::errorCode() only retrieves error codes for operations performed with PDOStatement objects.

範例

範例 1. Retrieving a SQLSTATE code

<?php
/* Provoke an error -- the BONES table does not exist */
$err = $dbh->prepare('SELECT skull FROM bones');
$err->execute();

echo
"\nPDOStatement::errorCode(): ";
print
$err->errorCode();
?>

The above example will output:

PDOStatement::errorCode(): 42S02

參考

PDO::errorCode()
PDO::errorInfo()
PDOStatement::errorInfo()