PDOStatement::errorCode
(no version information, might be only in CVS)
PDOStatement::errorCode --
Fetch the error code associated with the last operation on the statement handle
Description
int
PDOStatement::errorCode ( void )
警告 |
この関数は、
実験的なステータスにあります。これは、この関数の
動作、関数名、ここで書かれていること全てがPHPの将来のバージョンで予告
なく変更される可能性があることを意味します。注意を喚起するとともに自分
のリスクでこの関数を使用して下さい。 |
Returns an integer value that maps to the error categories defined
in the PDO constants.
例 1. Determining which category of error occurred
<?php /* Provoke an error -- the BONES table does not exist */ $err = $dbh->prepare('SELECT skull FROM bones'); $err->execute();
echo "\nPDOStatement::errorCode(): "; switch ($err->errorCode()) { case PDO_ERR_NONE: echo "No error!\n"; break; case PDO_ERR_CANT_MAP: echo "Error: Unable to map data types between database and PHP.\n"; break; case PDO_ERR_SYNTAX: echo "Error: incorrect syntax\n"; break; case PDO_ERR_CONSTRAINT: echo "Error: The request would violate a constraint.\n"; break; case PDO_ERR_NOT_FOUND: echo "Error: The object could not be found.\n"; break; case PDO_ERR_ALREADY_EXISTS: echo "Error: The object already exists.\n"; break; case PDO_ERR_NOT_IMPLEMENTED: echo "Error: The requested function is not implemented.\n"; break; case PDO_ERR_MISMATCH: echo "Error: mismatch\n"; break; case PDO_ERR_TRUNCATED: echo "Error: The value was truncated because the input value was longer than the maximum column length.\n"; break; case PDO_ERR_DISCONNECTED: echo "Error: The connection to the requested database has been closed.\n"; break; } ?>
|
|
上の例の出力は以下となります:
PDOStatement::errorCode(): Error: The object could not be found. |