Mega Code Archive

 
Categories / Php / Development
 

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();    } ?>