Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 1.22 KB

File metadata and controls

46 lines (34 loc) · 1.22 KB
title PDOStatement::errorCode
description API reference for the PDOStatement::errorCode function in the Microsoft PDO_SQLSRV Driver for PHP for SQL Server.
author David-Engel
ms.author davidengel
ms.date 08/10/2020
ms.service sql
ms.subservice connectivity
ms.topic reference

PDOStatement::errorCode

[!INCLUDEDriver_PHP_Download]

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 [!INCLUDEssDriverPHP].

Example

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();  
?>  

See Also

PDOStatement Class

PDO