pdo.error-handling.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 91 行

HTML
91
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Errors and error handling</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.prepared-statements.html">Prepared statements and stored procedures</a></div> <div class="next" style="text-align: right; float: right;"><a href="pdo.lobs.html">Large Objects (LOBs)</a></div> <div class="up"><a href="book.pdo.html">PDO</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div> <h1>Errors and error handling</h1> <p class="para">  PDO offers you a choice of 3 different error handling strategies, to fit  your style of application development. </p> <ul class="itemizedlist">  <li class="listitem">   <p class="para">    <b><tt>PDO::ERRMODE_SILENT</tt></b>   </p>   <p class="para">     This is the default mode. PDO will simply set the error code for you     to inspect using the <a href="pdo.errorcode.html" class="function">PDO::errorCode()</a> and     <a href="pdo.errorinfo.html" class="function">PDO::errorInfo()</a> methods on both the     statement and database objects; if the error resulted from a call on a     statement object, you would invoke the     <a href="pdostatement.errorcode.html" class="function">PDOStatement::errorCode()</a> or     <a href="pdostatement.errorinfo.html" class="function">PDOStatement::errorInfo()</a>     method on that object. If the error resulted from a call on the     database object, you would invoke those methods on the database object     instead.    </p>  </li>  <li class="listitem">   <p class="para">    <b><tt>PDO::ERRMODE_WARNING</tt></b>   </p>   <p class="para">     In addition to setting the error code, PDO will emit a traditional     E_WARNING message. This setting is useful during debugging/testing, if     you just want to see what problems occurred without interrupting the     flow of the application.    </p>   </li>   <li class="listitem">    <p class="para">     <b><tt>PDO::ERRMODE_EXCEPTION</tt></b>    </p>    <p class="para">     In addition to setting the error code, PDO will throw a     <a href="class.pdoexception.html" class="classname">PDOException</a>     and set its properties to reflect the error code and error     information. This setting is also useful during debugging, as it will     effectively &quot;blow up&quot; the script at the point of the error, very     quickly pointing a finger at potential problem areas in your code     (remember: transactions are automatically rolled back if the exception     causes the script to terminate).    </p>    <p class="para">     Exception mode is also useful because you can structure your error     handling more clearly than with traditional PHP-style warnings, and     with less code/nesting than by running in silent mode and explicitly     checking the return value of each database call.    </p>    <p class="para">     See <a href="language.exceptions.html" class="link">Exceptions</a> for more     information about Exceptions in PHP.    </p>   </li> </ul> <p class="para">  PDO standardizes on using SQL-92 SQLSTATE error code strings; individual  PDO drivers are responsible for mapping their native codes to the  appropriate SQLSTATE codes.   The <a href="pdo.errorcode.html" class="function">PDO::errorCode()</a>  method returns a single SQLSTATE code. If you need more specific  information about an error, PDO also offers an  <a href="pdo.errorinfo.html" class="function">PDO::errorInfo()</a> method which returns an array  containing the SQLSTATE code, the driver specific error code and driver  specific error string. </p></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="pdo.prepared-statements.html">Prepared statements and stored procedures</a></div> <div class="next" style="text-align: right; float: right;"><a href="pdo.lobs.html">Large Objects (LOBs)</a></div> <div class="up"><a href="book.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 + =
减小字号Ctrl + -
显示快捷键?