php - PDOException not being caught? -
i'm getting following error in php:
fatal error: uncaught exception 'pdoexception' message 'sqlstate[hy000] [2003] can't connect mysql server on 'localhost' (10061)' in c:\xampp\htdocs\project\service\database.class.php:26 stack trace: #0 c:\xampp\htdocs\project\service\database.class.php(26): pdo->__construct('mysql:host=loca...', 'root', '', array) #1 c:\xampp\htdocs\project\service\database.class.php(54): service\database::initialize() #2 c:\xampp\htdocs\project\index.php(15): service\database::gethandler() #3 {main} thrown in c:\xampp\htdocs\project\service\database.class.php on line 26 the error not problem, intentionally terminated mysql service in windows see happened (i'm using xampp). problem i'm unable catch exception pdo object throws , don't know why.
try { $host = "localhost"; $dbname = "project"; $username = "root"; $password = ""; $charset = "utf8"; $dsn = "mysql:host=$host;dbname=$dbname;charset=$charset"; $driveroptions = array( pdo::mysql_attr_init_command => "set names $charset" ); // line supposedly throws exception (line 26): $dbh = new pdo($dsn, $username, $password, $driveroptions); $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception); self::sethandler($dbh); } catch (pdoexception $e) { die("catched"); // line never reached } catch (exception $e) { die("catched"); // nor one. } what missing here?
the thing can think of if you're inside namespaced class, , should use \pdoexception instead of pdoexception.
Comments
Post a Comment