<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Returns error and warning information about the last SQLSRV operation performed</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlsrv-connect.html">sqlsrv_connect</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlsrv-execute.html">sqlsrv_execute</a></div> <div class="up"><a href="ref.sqlsrv.html">SQLSRV Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.sqlsrv-errors" class="refentry"> <div class="refnamediv"> <h1 class="refname">sqlsrv_errors</h1> <p class="verinfo">(No version information available, might only be in SVN)</p><p class="refpurpose"><span class="refname">sqlsrv_errors</span> — <span class="dc-title">Returns error and warning information about the last SQLSRV operation performed</span></p> </div> <div class="refsect1 description" id="refsect1-function.sqlsrv-errors-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>sqlsrv_errors</strong></span> ([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$errorsOrWarnings</code></span> ] )</div> <p class="para rdfs-comment"> Returns error and warning information about the last SQLSRV operation performed. </p> </div> <div class="refsect1 parameters" id="refsect1-function.sqlsrv-errors-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">errorsOrWarnings</code></em></span> <dd> <p class="para"> Determines whether error information, warning information, or both are returned. If this parameter is not supplied, both error information and warning information are returned. The following are the supported values for this parameter: SQLSRV_ERR_ALL, SQLSRV_ERR_ERRORS, SQLSRV_ERR_WARNINGS. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.sqlsrv-errors-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> If errors and/or warnings occurred on the last sqlsrv operation, an array of arrays containing error information is returned. If no errors and/or warnings occurred on the last sqlsrv operation, <strong><code>NULL</code></strong> is returned. The following table describes the structure of the returned arrays: <table class="doctable table"> <caption><strong>Array returned by sqlsrv_errors</strong></caption> <thead> <tr> <th>Key</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>SQLSTATE</td> <td>For errors that originate from the ODBC driver, the SQLSTATE returned by ODBC. For errors that originate from the Microsoft Drivers for PHP for SQL Server, a SQLSTATE of IMSSP. For warnings that originate from the Microsoft Drivers for PHP for SQL Server, a SQLSTATE of 01SSP. </td> </tr> <tr> <td>code</td> <td>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 Microsoft Drivers for PHP for SQL Server, the Microsoft Drivers for PHP for SQL Server error code. </td> </tr> <tr> <td>message</td> <td>A description of the error.</td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.sqlsrv-errors-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2175"> <p><strong>Example #1 <span class="function"><strong>functionname()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$serverName </span><span style="color: #007700">= </span><span style="color: #DD0000">"serverName/sqlexpress"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$connectionInfo </span><span style="color: #007700">= array( </span><span style="color: #DD0000">"Database"</span><span style="color: #007700">=></span><span style="color: #DD0000">"dbName"</span><span style="color: #007700">, </span><span style="color: #DD0000">"UID"</span><span style="color: #007700">=></span><span style="color: #DD0000">"username"</span><span style="color: #007700">, </span><span style="color: #DD0000">"PWD"</span><span style="color: #007700">=></span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlsrv_connect</span><span style="color: #007700">( </span><span style="color: #0000BB">$serverName</span><span style="color: #007700">, </span><span style="color: #0000BB">$connectionInfo</span><span style="color: #007700">);<br />if( </span><span style="color: #0000BB">$conn </span><span style="color: #007700">=== </span><span style="color: #0000BB">false </span><span style="color: #007700">) {<br /> die( </span><span style="color: #0000BB">print_r</span><span style="color: #007700">( </span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(), </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #FF8000">/* Set up a query to select an invalid column name. */<br /></span><span style="color: #0000BB">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT BadColumnName FROM Table_1"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* Execution of the query will fail because of the bad column name. */<br /></span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlsrv_query</span><span style="color: #007700">( </span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #0000BB">$sql </span><span style="color: #007700">);<br />if( </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">=== </span><span style="color: #0000BB">false </span><span style="color: #007700">) {<br /> if( (</span><span style="color: #0000BB">$errors </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">() ) != </span><span style="color: #0000BB">null</span><span style="color: #007700">) {<br /> foreach( </span><span style="color: #0000BB">$errors </span><span style="color: #007700">as </span><span style="color: #0000BB">$error </span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"SQLSTATE: "</span><span style="color: #007700">.</span><span style="color: #0000BB">$error</span><span style="color: #007700">[ </span><span style="color: #DD0000">'SQLSTATE'</span><span style="color: #007700">].</span><span style="color: #DD0000">"<br />"</span><span style="color: #007700">;<br /> echo </span><span style="color: #DD0000">"code: "</span><span style="color: #007700">.</span><span style="color: #0000BB">$error</span><span style="color: #007700">[ </span><span style="color: #DD0000">'code'</span><span style="color: #007700">].</span><span style="color: #DD0000">"<br />"</span><span style="color: #007700">;<br /> echo </span><span style="color: #DD0000">"message: "</span><span style="color: #007700">.</span><span style="color: #0000BB">$error</span><span style="color: #007700">[ </span><span style="color: #DD0000">'message'</span><span style="color: #007700">].</span><span style="color: #DD0000">"<br />"</span><span style="color: #007700">;<br /> }<br /> }<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.sqlsrv-errors-notes"> <h3 class="title">Notes</h3> <p class="para"> By default, warnings generated on a call to any SQLSRV function are treated as errors. This means that if a warning occurs on a call to a SQLSRV function, the function returns <strong><code>FALSE</code></strong>. However, warnings that correspond to SQLSTATE values 01000, 01001, 01003, and 01S02 are never treated as errors. For information about changing this behavior, see <span class="function"><a href="function.sqlsrv-configure.html" class="function">sqlsrv_configure()</a></span> and the WarningsReturnAsErrors setting. </p> </div> <div class="refsect1 seealso" id="refsect1-function.sqlsrv-errors-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.sqlsrv-configure.html" class="function" rel="rdfs-seeAlso">sqlsrv_configure()</a> - Changes the driver error handling and logging configurations</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlsrv-connect.html">sqlsrv_connect</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlsrv-execute.html">sqlsrv_execute</a></div> <div class="up"><a href="ref.sqlsrv.html">SQLSRV Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>