Catch database connection exception
<?php
try {
$conn = mysql_connect("localhost","username","password");
if (! $conn) {
throw new Exception("Could not connect!");
}
}
catch (Exception $e) {
echo "Error (File: ".getFile().", line ".$e->getLine()."): ".$e->getMessage();
}
?>
Related examples in the same category