--- title: "PDOStatement::errorCode | Microsoft Docs" ms.custom: "" ms.date: "01/19/2017" ms.prod: sql ms.prod_service: connectivity ms.reviewer: "" ms.technology: connectivity ms.topic: conceptual ms.assetid: 4161abec-c12b-444e-9de5-f1dac7b3e0e4 author: David-Engel ms.author: v-daenge --- # PDOStatement::errorCode [!INCLUDE[Driver_PHP_Download](../../includes/driver_php_download.md)] Retrieves the SQLSTATE of the most recent operation on the database statement object. ## Syntax ``` string PDOStatement::errorCode(); ``` ## Return Value Returns a five-char SQLSTATE as a string, or NULL if there was no operation on the statement handle. ## Remarks Support for PDO was added in version 2.0 of the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)]. ## Example This example shows a SQL query that has an error. The error code is then displayed. ``` prepare('SELECT * FROM Person.Addressx'); $stmt->execute(); print $stmt->errorCode(); ?> ``` ## See Also [PDOStatement Class](../../connect/php/pdostatement-class.md) [PDO](https://php.net/manual/book.pdo.php)