Source of: /manual/en/pdostatement.errorcode.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.pdostatement.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'pdostatement.errorcode.php',
1 => 'PDOStatement->errorCode',
),
'up' =>
array (
0 => 'class.pdostatement.php',
1 => 'The PDOStatement class',
),
'prev' =>
array (
0 => 'pdostatement.debugdumpparams.php',
1 => 'PDOStatement->debugDumpParams',
),
'next' =>
array (
0 => 'pdostatement.errorinfo.php',
1 => 'PDOStatement->errorInfo',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="pdostatement.errorcode" class="refentry">
<div class="refnamediv">
<h1 class="refname">PDOStatement->errorCode</h1>
<p class="verinfo">(PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)</p><p class="refpurpose"><span class="refname">PDOStatement->errorCode</span> — <span class="dc-title">
Fetch the SQLSTATE associated with the last operation on the statement handle
</span></p>
</div>
<a name="pdostatement.errorcode.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">string</span> <span class="methodname"><b>PDOStatement::errorCode</b></span>
( <span class="methodparam">void</span>
)</div>
</div>
<a name="pdostatement.errorcode.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Identical to <a href="pdo.errorcode.php" class="function">PDO::errorCode()</a>, except that
<b>PDOStatement::errorCode()</b> only retrieves error codes
for operations performed with PDOStatement objects.
</p>
</div>
<a name="pdostatement.errorcode.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example"><p><b>Example #1 Retrieving a SQLSTATE code</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Provoke an error -- the BONES table does not exist */<br /></span><span style="color: #0000BB">$err </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-></span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">'SELECT skull FROM bones'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$err</span><span style="color: #007700">-></span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br />echo </span><span style="color: #DD0000">"\nPDOStatement::errorCode(): "</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">$err</span><span style="color: #007700">-></span><span style="color: #0000BB">errorCode</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
<div class="example-contents para"><p>The above example will output:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
PDOStatement::errorCode(): 42S02
</pre></div>
</div>
</div><p>
</p>
</div>
<a name="pdostatement.errorcode.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="pdo.errorcode.php" class="function" rel="rdfs-seeAlso">PDO::errorCode()</a> - Fetch the SQLSTATE associated with the last operation on the database handle</li>
<li class="member"><a href="pdo.errorinfo.php" class="function" rel="rdfs-seeAlso">PDO::errorInfo()</a> - Fetch extended error information associated with the last operation on the database handle</li>
<li class="member"><a href="pdostatement.errorinfo.php" class="function" rel="rdfs-seeAlso">PDOStatement::errorInfo()</a> - Fetch extended error information associated with the last operation on the statement handle</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>