Include an example of how to set the PDO error mode

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@313120 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Joey Smith 2011-07-10 20:20:09 +00:00
parent 23fed62e91
commit 763c810f70

View file

@ -72,6 +72,31 @@
containing the SQLSTATE code, the driver specific error code and driver
specific error string.
</para>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example><title>Create a PDO instance and set the error mode</title>
<programlisting role="php">
<![CDATA[
<?php
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';
try {
$dbh = new PDO($dsn, $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
</chapter>
<!-- Keep this comment at the end of the file