<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="pdo.errorcode" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>PDO::errorCode</refname>
  <refpurpose>
   Fetch the SQLSTATE associated with the last operation on the database handle
  </refpurpose>
 </refnamediv>
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis role="PDO">
   <modifier>public</modifier> <type class="union"><type>string</type><type>null</type></type><methodname>PDO::errorCode</methodname>
   <void/>
  </methodsynopsis>

 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  &no.function.parameters;
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <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 '01', except for the
   class 'IM', indicate an error.  The class 'IM' is specific to warnings
   and errors that derive from the implementation of PDO (or perhaps ODBC,
   if you're using the ODBC driver) itself.  The subclass value '000' in any
   class indicates that there is no subclass for that SQLSTATE.
  </para>
  <para>
   <methodname>PDO::errorCode</methodname> only retrieves error codes for operations
   performed directly on the database handle. If you create a PDOStatement
   object through <methodname>PDO::prepare</methodname> or
   <methodname>PDO::query</methodname> and invoke an error on the statement
   handle, <methodname>PDO::errorCode</methodname> will not reflect that error.
   You must call <methodname>PDOStatement::errorCode</methodname> to return the error
   code for an operation performed on a particular statement handle.
  </para>
  <para>
   Returns &null; if no operation has been run on the database handle.
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example><title>Retrieving an SQLSTATE code</title>
    <programlisting role="php">
<![CDATA[
<?php
/* Provoke an error -- the BONES table does not exist */
$dbh->exec("INSERT INTO bones(skull) VALUES ('lucy')");

echo "\nPDO::errorCode(): ", $dbh->errorCode();
?>
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
PDO::errorCode(): 42S02
]]>
    </screen>
   </example>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><methodname>PDO::errorInfo</methodname></member>
    <member><methodname>PDOStatement::errorCode</methodname></member>
    <member><methodname>PDOStatement::errorInfo</methodname></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
