mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
23fed62e91
commit
763c810f70
1 changed files with 25 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue