I am trying to instantiate a PDO object as follows:
$this->pdo['pdo'] = new PDO('mysql:host=127.0.0.1;dbname=mydb;charset=UTF-8', 'myuser', 'my pass');
I would like to get an exception that I thought would be thrown when the MySQL server is not running.
PHP.net says: "PDO :: __ construct () throws a PDOException if an attempt to connect to the requested database fails."
But if I close the database server and run the script, all I get is a warning:
Warning: PDO::__construct() [pdo.--construct]: [2002] 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.' in C:\test\test.php on line 5 Fatal error: Maximum execution time of 60 seconds exceeded in C:\test\test.php on line 0
No exception is thrown.
Is there a direct way to catch the error (without the hassle of temporarily setting up the function of the custom error manager?)
Thanks!
source share