php-doc-en/reference/pdo/functions/PDO-errorInfo.xml
2004-11-26 20:12:46 +00:00

114 lines
3.3 KiB
XML

<?xml version='1.0' encoding='iso-8859-1'?>
<!-- $Revision: 1.3 $ -->
<!-- Generated by xml_proto.php v2.1. Found in /scripts directory of phpdoc. -->
<refentry id="function.PDO-errorInfo">
<refnamediv>
<refname>PDO::errorInfo</refname>
<refpurpose>
Fetch extended error information associated with the last operation on the database handle
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>array</type><methodname>PDO::errorInfo</methodname>
<void/>
</methodsynopsis>
&warn.experimental.func;
<para>
<function>PDO::errorInfo</function> returns an array of error information
about the last operation performed by this database handle. The array
consists of the following fields:
<informaltable>
<tgroup cols='2'>
<thead>
<row>
<entry>Element</entry>
<entry>Information</entry>
</row>
</thead>
<tbody>
<row>
<entry>0</entry>
<entry>Generic PDO error code corresponding to one of the
<literal>PDO_ERR_*</literal> constants.</entry>
</row>
<row>
<entry>1</entry>
<entry>Driver-specific error code.</entry>
</row>
<row>
<entry>2</entry>
<entry>Driver-specific error message.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<para>
<function>PDO::errorInfo</function> only retrieves error information
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::errorInfo</function> will insert an error code
of <literal>PDO_ERR_NONE</literal> into the first element of the returned
array. You must call <function>PDOStatement::errorInfo</function> to
return the error information for an operation performed on a particular
statement handle.
</para>
<example><title>Displaying errorInfo() fields for a PDO_ODBC connection to a DB2 database</title>
<programlisting role="php">
<![CDATA[
<?php
/* Provoke an error -- the BONES table does not exist */
$dbh->exec("INSERT INTO bones(skull) VALUES ('reagan')");
$arr = $dbh->errorInfo();
if ($arr[0] == PDO_ERR_NOT_FOUND) {
echo "Error: a requested database object does not exist.\n";
printf("Driver-specific error code: %d\n", $arr[1]);
printf("Driver-specific message: [%s]\n", $arr[2]);
}
?>
]]>
</programlisting>
</example>
&example.outputs;
<screen>
<![CDATA[
Error: a requested database object does not exist.
Driver-specific error code: -204
Driver-specific message: [SQLExecute: -204 [IBM][CLI Driver][DB2/NT]
SQL0204N "DB2INST1.BONES" is an undefined name. SQLSTATE=42704
[SQL State 42S02] (..\pecl\pdo_odbc\odbc_stmt.c:80)]
]]>
</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
-->