php-doc-en/reference/pdo/functions/PDOStatement-errorCode.xml

98 lines
2.7 KiB
XML
Raw Normal View History

<?xml version='1.0' encoding='iso-8859-1'?>
<!-- $Revision: 1.2 $ -->
<!-- Generated by xml_proto.php v2.1. Found in /scripts directory of phpdoc. -->
<refentry id="function.PDOStatement-errorCode">
<refnamediv>
<refname>PDOStatement::errorCode</refname>
<refpurpose>
Fetch the error code associated with the last operation on the statement handle
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>PDOStatement::errorCode</methodname>
<void/>
</methodsynopsis>
&warn.experimental.func;
<para>
Returns an integer value that maps to the error categories defined
in the PDO constants.
</para>
<example><title>Determining which category of error occurred</title>
<programlisting role="php">
<![CDATA[
<?php
/* Provoke an error -- the BONES table does not exist */
$err = $dbh->prepare('SELECT skull FROM bones');
$err->execute();
echo "\nPDOStatement::errorCode(): ";
switch ($err->errorCode()) {
case PDO_ERR_NONE:
echo "No error!\n";
break;
case PDO_ERR_CANT_MAP:
echo "Error: Unable to map data types between database and PHP.\n";
break;
case PDO_ERR_SYNTAX:
echo "Error: incorrect syntax\n";
break;
case PDO_ERR_CONSTRAINT:
echo "Error: The request would violate a constraint.\n";
break;
case PDO_ERR_NOT_FOUND:
echo "Error: The object could not be found.\n";
break;
case PDO_ERR_ALREADY_EXISTS:
echo "Error: The object already exists.\n";
break;
case PDO_ERR_NOT_IMPLEMENTED:
echo "Error: The requested function is not implemented.\n";
break;
case PDO_ERR_MISMATCH:
echo "Error: mismatch\n";
break;
case PDO_ERR_TRUNCATED:
echo "Error: The value was truncated because the input value was longer
than the maximum column length.\n";
break;
case PDO_ERR_DISCONNECTED:
echo "Error: The connection to the requested database has been closed.\n";
break;
}
?>
]]>
</programlisting>
</example>
&example.outputs;
<screen>
<![CDATA[
PDOStatement::errorCode(): Error: The object could not be found.
]]>
</screen>
</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
-->