PDO::errorInfo

Microsoft Drivers for PHP for SQL Server

Collapse image Expand Image Copy image CopyHover image

Retrieves extended error information of the most recent operation on the database handle.

Syntax

array PDO::errorInfo();

Return Value

An array of error information about the most recent operation on the database handle. The array consists of the following fields:

  • The SQLSTATE error code.

  • The driver-specific error code.

  • The driver-specific error message.

If there is no error, or if the SQLSTATE is not set, the driver-specific fields will be NULL.

Remarks

PDO::errorInfo only retrieves error information for operations performed directly on the database. Use PDOStatement::errorInfo when a PDOStatement instance is created using PDO::prepare or PDO::query.

Support for PDO was added in version 2.0 of the Microsoft Drivers for PHP for SQL Server.

Example

In this example, the name of the column is misspelled (Cityx instead of City), causing an error, which is then reported.

  Copy imageCopy Code
<?php
$conn = new PDO( "sqlsrv:server=(local) ; Database = AdventureWorks ", "");
$query = "SELECT * FROM Person.Address where Cityx = 'Essen'";

$conn->query($query);
print $conn->errorCode();
echo "\n";
print_r ($conn->errorInfo());
?>

See Also

Reference

Other Resources

PDO