title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic |
---|---|---|---|---|---|---|---|
PDOStatement::errorCode |
API reference for the PDOStatement::errorCode function in the Microsoft PDO_SQLSRV Driver for PHP for SQL Server. |
David-Engel |
v-davidengel |
08/10/2020 |
sql |
connectivity |
reference |
[!INCLUDEDriver_PHP_Download]
Retrieves the SQLSTATE of the most recent operation on the database statement object.
string PDOStatement::errorCode();
Returns a five-char SQLSTATE as a string, or NULL if there was no operation on the statement handle.
Support for PDO was added in version 2.0 of the [!INCLUDEssDriverPHP].
This example shows a SQL query that has an error. The error code is then displayed.
<?php
$conn = new PDO( "sqlsrv:server=(local) ; Database = AdventureWorks", "", "");
$stmt = $conn->prepare('SELECT * FROM Person.Addressx');
$stmt->execute();
print $stmt->errorCode();
?>