Catch database connection exception : Exceptions : Development PHP Source Code


PHP Source Code » Development » Exceptions »

 

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

?>

           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Development
» Exceptions