Created
February 7, 2013 11:21
-
-
Save coreymcmahon/4730388 to your computer and use it in GitHub Desktop.
Using PDO for database access - handling errors. From the article: PDO for Elegant PHP Database Access, http://www.modernphpbook.com/articles/pdo-for-elegant-php-database-access - Fig 9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try { | |
$conn = new PDO('mysql:host=localhost;dbname=someDb', $username, $password); | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
// run queries... | |
} catch (PDOException $ex) { | |
echo "Error: " . $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment