diff --git a/reference/pdo/functions/PDO-errorCode.xml b/reference/pdo/functions/PDO-errorCode.xml index 8b2f7a5246..d12418e589 100644 --- a/reference/pdo/functions/PDO-errorCode.xml +++ b/reference/pdo/functions/PDO-errorCode.xml @@ -1,5 +1,5 @@ - + @@ -15,7 +15,72 @@ - &warn.undocumented.func; + &warn.experimental.func; + + Returns an integer value that maps to the generic error categories + defined in the PDO_ERR_* set of constants. + + + 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 return + PDO_ERR_NONE. You must call + PDOStatement::errorCode to return the error + code for an operation performed on a particular statement handle. + + Determining which category of error occurred + +exec("INSERT INTO bones(skull) VALUES ('reagan')"); + +echo "\nPDO::errorCode(): "; +switch ($dbh->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; +} +?> +]]> + + + &example.outputs; + + + diff --git a/reference/pdo/functions/PDO-errorInfo.xml b/reference/pdo/functions/PDO-errorInfo.xml index 785ba24049..2336193803 100644 --- a/reference/pdo/functions/PDO-errorInfo.xml +++ b/reference/pdo/functions/PDO-errorInfo.xml @@ -1,5 +1,5 @@ - + @@ -15,7 +15,79 @@ - &warn.undocumented.func; + &warn.experimental.func; + + + PDO::errorInfo returns an array of error information + about the last operation performed by this database handle. The array + consists of the following fields: + + + + + Element + Information + + + + + 0 + Generic PDO error code corresponding to one of the + PDO_ERR_* constants. + + + 1 + Driver-specific error code. + + + 2 + Driver-specific error message. + + + + + + + + PDO::errorInfo only retrieves error information + 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::errorInfo will insert an error code + of PDO_ERR_NONE into the first element of the returned + array. You must call PDOStatement::errorInfo to + return the error information for an operation performed on a particular + statement handle. + + + Displaying errorInfo() fields for a PDO_ODBC connection to a DB2 database + +exec("INSERT INTO bones(skull) VALUES ('reagan')"); + +$arr = $dbh->errorInfo(); +if ($arr[0] == PDO_ERR_NOT_FOUND) { + echo "Error: a requested database object does not exist.\n"; + printf("Driver-specific error code: %d\n", $arr[1]); + printf("Driver-specific message: [%s]\n", $arr[2]); +} +?> +]]> + + + &example.outputs; + + + +