php-doc-en/reference/pdo/functions/PDO-errorCode.xml
Antony Dovgal 2c30b31288 fix return types (int -> string)
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@200473 c90b9560-bf6c-de11-be94-00142212c4b1
2005-11-14 09:20:39 +00:00

101 lines
3.1 KiB
XML

<?xml version='1.0' encoding='iso-8859-1'?>
<!-- $Revision: 1.7 $ -->
<!-- Generated by xml_proto.php v2.1. Found in /scripts directory of phpdoc. -->
<refentry id="function.PDO-errorCode">
<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>
<type>string</type><methodname>PDO::errorCode</methodname>
<void/>
</methodsynopsis>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a SQLSTATE, a five-character alphanumeric identifier defined in
the ANSI SQL-92 standard. Briefly, an SQLSTATE consists of a
two-character class value followed by a three-character 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>
<function>PDO::errorCode</function> only retrieves error codes for operations
performed directly on the database handle. If you create a PDOStatement
object through <function>PDO::prepare</function> or
<function>PDO::query</function> and invoke an error on the statement
handle, <function>PDO::errorCode</function> will not reflect that error.
You must call <function>PDOStatement::errorCode</function> to return the error
code for an operation performed on a particular statement handle.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example><title>Retrieving a 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(): ";
print $dbh->errorCode();
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
PDO::errorCode(): 42S02
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>PDO::errorInfo</function></member>
<member><function>PDOStatement::errorCode</function></member>
<member><function>PDOStatement::errorInfo</function></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:"../../../../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
-->