Catch database connection exception : Exceptions « Development « PHP






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

1.Define your own exception class