I am writing an installer for one of my apps and I would like to be able to test some default database settings.
Is this possible using PDO to test valid and invalid database connections?
I have the following code:
try{ $dbh = new pdo('mysql:host=127.0.0.1:3308;dbname=axpdb','admin','1234'); die(json_encode(array('outcome' => true))); }catch(PDOException $ex){ die(json_encode(array( 'outcome' => false, 'message' => 'Unable to connect' ))); } The problem I am having is that the script trys to connect until the script execution time of 60 seconds runs out instead of saying it cannot connect to the db.
Thanks
PDO? everything else looks fine for me.PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION?$dbh = new PDO('mysql:host=127.0.0.1;port=3308;dbname=axpdb','admin','1234', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));it makes no difference and as it is that line that errors i cannot do$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );below