Hi All,
I'm new in PHP and MySql, I did Ms VS .Net programming as well. Just wonder how am I going to
write PHP code to capture the expectional error during connecting to MySQL database. In .Net
there is something like try and catch?
Thanks
Cheers!
How to capture exceptional error when connect to Mysql DB
Moderator: General Moderators
But PDO throws excpetions. Simple examplesee http://de3.php.net/pdo
Code: Select all
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', 'wronguser', 'wrongpass', array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
// ...
}
catch(PDOException $e) {
die('exception: ' . $e->getMessage() );
}
?>