php - Exceptionally bad at understanding exceptions -


so busy moving on pdo (yes, i'm still oldschool mysql driver that) , have never used exceptions before. code below based on understand far. application needing create 3 seperate database connections, 2 of mysql , 1 mssql (hence type if else).

the problem if provide incorrect connection values, still processes , continues script, , skips "catch" entirely, if there no error. understand basics should be:

 try {       if("condition" != "conditions") {            throw new exception("oops did again");       }  catch(exceptions e) {        echo $e->getmessage();  } 

i understand pdo through exceptions dont have throw, it's not working out, please , give me bit more oversight misunderstanding concept:

 // connect(): connect database (mysql):  private function connect($cred) {     $type = $cred['type'];     if($type == "mysql") {         try {             $handler = new pdo("mysql:host".$cred['credentials']['server'].";dbname=".$cred['credentials']['database'].", ".$cred['credentials']['username'].",".$cred['credentials']['password']);             if($cred['errors'] == 'exception') {                 $handler->setattribute( pdo::attr_errmode, pdo::errmode_exception );             } elseif($cred['errors'] == 'warning') {                 $handler->setattribute( pdo::attr_errmode, pdo::errmode_warning );             } else {                 $handler->setattribute( pdo::attr_errmode, pdo::errmode_silent );             }         }         catch(pdoexception $e) {             $this->informer("fatal","an error has occured trying connect connection (".$cred['name'].") -".$e->getmessage());             return false;         }         return $handler;     } } 

found issue, syntax issue above in pdo objection creation, had:

 $handler = new pdo("mysql:host".$cred['credentials']['server'].";dbname=".$cred['credentials']['database'].", ".$cred['credentials']['username'].",".$cred['credentials']['password']); 

and should have been:

 $handler = new pdo("mysql:host=".$cred['credentials']['server'].";dbname=".$cred['credentials']['database'].", ".$cred['credentials']['username'].",".$cred['credentials']['password']); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -