--- title: "sqlsrv_errors | Microsoft Docs" ms.custom: "" ms.date: "01/19/2017" ms.prod: sql ms.prod_service: connectivity ms.reviewer: "" ms.technology: connectivity ms.topic: conceptual apiname: - "sqlsrv_errors" apitype: "NA" helpviewer_keywords: - "API Reference, sqlsrv_errors" - "sqlsrv_errors" - "errors and warnings" ms.assetid: d1fcffec-f34f-46de-9a0e-343f3b5dbae2 author: David-Engel ms.author: v-daenge --- # sqlsrv_errors [!INCLUDE[Driver_PHP_Download](../../includes/driver_php_download.md)] Returns extended error and/or warning information about the last **sqlsrv** operation performed. The **sqlsrv_errors** function can return error and/or warning information by calling it with one of the parameter values specified in the Parameters section below. By default, warnings generated on a call to any **sqlsrv** function are treated as errors; if a warning occurs on a call to a **sqlsrv** function, the function returns false. However, warnings that correspond to SQLSTATE values 01000, 01001, 01003, and 01S02 are never treated as errors. The following line of code turns off the behavior mentioned above; a warning generated by a call to a **sqlsrv** function does not cause the function to return false: ``` sqlsrv_configure("WarningsReturnAsErrors", 0); ``` The following line of code reinstates the default behavior; warnings (with exceptions, noted above) are treated as errors: ``` sqlsrv_configure("WarningsReturnAsErrors", 1); ``` Regardless of the setting, warnings can only be retrieved by calling **sqlsrv_errors** with either the **SQLSRV_ERR_ALL** or **SQLSRV_ERR_WARNINGS** parameter value (see Parameters section below for details). ## Syntax ``` sqlsrv_errors( [int $errorsAndOrWarnings] ) ``` #### Parameters *$errorsAndOrWarnings*[OPTIONAL]: A predefined constant. This parameter can take one of the values listed in the following table: |Value|Description| |---------|---------------| |SQLSRV_ERR_ALL|Errors and warnings generated on the last **sqlsrv** function call are returned.| |SQLSRV_ERR_ERRORS|Errors generated on the last **sqlsrv** function call are returned.| |SQLSRV_ERR_WARNINGS|Warnings generated on the last **sqlsrv** function call are returned.| If no parameter value is supplied, both errors and warnings generated by the last **sqlsrv** function call are returned. ## Return Value An **array** of arrays, or **null**. Each **array** in the returned **array** contains three key-value pairs. The following table lists each key and its description: |Key|Description| |-------|---------------| |SQLSTATE|For errors that originate from the ODBC driver, the SQLSTATE returned by ODBC. For information about SQLSTATE values for ODBC, see [ODBC Error Codes](../../odbc/reference/appendixes/appendix-a-odbc-error-codes.md).

For errors that originate from the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)], a SQLSTATE of IMSSP.

For warnings that originate from the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)], a SQLSTATE of 01SSP.| |code|For errors that originate from SQL Server, the native SQL Server error code.

For errors that originate from the ODBC driver, the error code returned by ODBC.

For errors that originate from the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)], the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)] error code. For more information, see [Handling Errors and Warnings](../../connect/php/handling-errors-and-warnings.md).| |message|A description of the error.| The array values can also be accessed with numeric keys 0, 1, and 2. If no errors or warnings occur, **null** is returned. ## Example The following example displays errors that occur during a failed statement execution. (The statement fails because **InvalidColumName** is not a valid column name in the specified table.) The example assumes that SQL Server and the [AdventureWorks](https://github.com/Microsoft/sql-server-samples/tree/master/samples/databases/adventure-works) database are installed on the local computer. All output is written to the console when the example is run from the command line. ``` "AdventureWorks"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { echo "Could not connect.\n"; die( print_r( sqlsrv_errors(), true)); } /* Set up a query to select an invalid column name. */ $tsql = "SELECT InvalidColumnName FROM Sales.SalesOrderDetail"; /* Attempt execution. */ /* Execution will fail because of the invalid column name. */ $stmt = sqlsrv_query( $conn, $tsql); if( $stmt === false ) { if( ($errors = sqlsrv_errors() ) != null) { foreach( $errors as $error) { echo "SQLSTATE: ".$error[ 'SQLSTATE']."\n"; echo "code: ".$error[ 'code']."\n"; echo "message: ".$error[ 'message']."\n"; } } } /* Free connection resources */ sqlsrv_close( $conn); ?> ``` ## See Also [SQLSRV Driver API Reference](../../connect/php/sqlsrv-driver-api-reference.md) [About Code Examples in the Documentation](../../connect/php/about-code-examples-in-the-documentation.md)