<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.pdo.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'pdo.errorcode.php',
    1 => 'PDO::errorCode',
    2 => 'Fetch the SQLSTATE associated with the last operation on the database handle',
  ),
  'up' => 
  array (
    0 => 'class.pdo.php',
    1 => 'PDO',
  ),
  'prev' => 
  array (
    0 => 'pdo.construct.php',
    1 => 'PDO::__construct',
  ),
  'next' => 
  array (
    0 => 'pdo.errorinfo.php',
    1 => 'PDO::errorInfo',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pdo/pdo/errorcode.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdo.errorcode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDO::errorCode</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8, PECL pdo &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">PDO::errorCode</span> &mdash; <span class="dc-title">
   Fetch the SQLSTATE associated with the last operation on the database handle
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdo.errorcode-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDO::errorCode</strong></span>(): <span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span></div>


 </div>


 <div class="refsect1 parameters" id="refsect1-pdo.errorcode-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">This function has no parameters.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdo.errorcode-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an SQLSTATE, a five characters alphanumeric identifier defined in
   the ANSI SQL-92 standard.  Briefly, an SQLSTATE consists of a
   two characters class value followed by a three characters subclass value. A
   class value of 01 indicates a warning and is accompanied by a return code
   of SQL_SUCCESS_WITH_INFO. Class values other than &#039;01&#039;, except for the
   class &#039;IM&#039;, indicate an error.  The class &#039;IM&#039; is specific to warnings
   and errors that derive from the implementation of PDO (or perhaps ODBC,
   if you&#039;re using the ODBC driver) itself.  The subclass value &#039;000&#039; in any
   class indicates that there is no subclass for that SQLSTATE.
  </p>
  <p class="para">
   <span class="methodname"><strong>PDO::errorCode()</strong></span> only retrieves error codes for operations
   performed directly on the database handle. If you create a PDOStatement
   object through <span class="methodname"><a href="pdo.prepare.php" class="methodname">PDO::prepare()</a></span> or
   <span class="methodname"><a href="pdo.query.php" class="methodname">PDO::query()</a></span> and invoke an error on the statement
   handle, <span class="methodname"><strong>PDO::errorCode()</strong></span> will not reflect that error.
   You must call <span class="methodname"><a href="pdostatement.errorcode.php" class="methodname">PDOStatement::errorCode()</a></span> to return the error
   code for an operation performed on a particular statement handle.
  </p>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> if no operation has been run on the database handle.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdo.errorcode-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1"><p><strong>Example #1 Retrieving an SQLSTATE code</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* Provoke an error -- the BONES table does not exist */<br /></span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO bones(skull) VALUES ('lucy')"</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"\nPDO::errorCode(): "</span><span style="color: #007700">, </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errorCode</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">PDO::errorCode(): 42S02</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-pdo.errorcode-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="pdo.errorinfo.php" class="methodname" rel="rdfs-seeAlso">PDO::errorInfo()</a> - Fetch extended error information associated with the last operation on the database handle</span></li>
    <li><span class="methodname"><a href="pdostatement.errorcode.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::errorCode()</a> - Fetch the SQLSTATE associated with the last operation on the statement handle</span></li>
    <li><span class="methodname"><a href="pdostatement.errorinfo.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::errorInfo()</a> - Fetch extended error information associated with the last operation on the statement handle</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>