downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/pdo.error-handling.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/book.pdo.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'pdo.error-handling.php',
   
1 => 'Errors and error handling',
  ),
 
'up' =>
  array (
   
0 => 'book.pdo.php',
   
1 => 'PHP Data Objects',
  ),
 
'prev' =>
  array (
   
0 => 'pdo.prepared-statements.php',
   
1 => 'Prepared statements and stored procedures',
  ),
 
'next' =>
  array (
   
0 => 'pdo.lobs.php',
   
1 => 'Large Objects (LOBs)',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<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 class="constant">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.php" class="function">PDO::errorCode()</a> and
     <a href="pdo.errorinfo.php" 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.php" class="function">PDOStatement::errorCode()</a> or
     <a href="pdostatement.errorinfo.php" 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 class="constant">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 class="constant">PDO::ERRMODE_EXCEPTION</tt></b>
    </p>
    <p class="para">
     In addition to setting the error code, PDO will throw a
     <a href="class.pdoexception.php" 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.php" 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.php" 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.php" 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>
<?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites