📄 pdo.errorcode.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Fetch the SQLSTATE associated with the last operation on the database handle</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="pdo.construct.html">PDO::__construct</a></div> <div class="next" style="text-align: right; float: right;"><a href="pdo.errorinfo.html">PDO::errorInfo</a></div> <div class="up"><a href="class.pdo.html">PDO</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="pdo.errorcode" class="refentry"> <div class="refnamediv"> <h1 class="refname">PDO::errorCode</h1> <p class="verinfo">(PHP 5 >= 5.1.0, PECL pdo:0.1-1.0.3)</p><p class="refpurpose"><span class="refname">PDO::errorCode</span> — <span class="dc-title"> Fetch the SQLSTATE associated with the last operation on the database handle </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><b><b>PDO::errorCode</b></b></span> ( <span class="methodparam">void</span> )</div> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="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. </p> <p class="para"> <b>PDO::errorCode()</b> only retrieves error codes for operations performed directly on the database handle. If you create a PDOStatement object through <a href="pdo.prepare.html" class="function">PDO::prepare()</a> or <a href="pdo.query.html" class="function">PDO::query()</a> and invoke an error on the statement handle, <b>PDO::errorCode()</b> will not reflect that error. You must call <a href="pdostatement.errorcode.html" class="function">PDOStatement::errorCode()</a> to return the error code for an operation performed on a particular statement handle. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"><p><b>Example #1 Retrieving a SQLSTATE code</b></p> <div class="example-contents"><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">$dbh</span><span style="color: #007700">-></span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO bones(skull) VALUES ('lucy')"</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"\nPDO::errorCode(): "</span><span style="color: #007700">;<br />print </span><span style="color: #0000BB">$dbh</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"><p>The above example will output:</p></div> <div class="example-contents"><pre><div class="cdata"><pre>PDO::errorCode(): 42S02</pre></div> </pre></div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="pdo.errorinfo.html" class="function" rel="rdfs-seeAlso">PDO::errorInfo()</a></li> <li class="member"><a href="pdostatement.errorcode.html" class="function" rel="rdfs-seeAlso">PDOStatement::errorCode()</a></li> <li class="member"><a href="pdostatement.errorinfo.html" class="function" rel="rdfs-seeAlso">PDOStatement::errorInfo()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="pdo.construct.html">PDO::__construct</a></div> <div class="next" style="text-align: right; float: right;"><a href="pdo.errorinfo.html">PDO::errorInfo</a></div> <div class="up"><a href="class.pdo.html">PDO</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -