我试图像这样实例化一个PDO对象:
$this->pdo['pdo'] = new PDO('mysql:host=127.0.0.1;dbname=mydb;charset=UTF-8',
'myuser', 'my pass');
我想抓住我认为在MySQL服务器没有运行时会抛出的异常.
PHP.net说“如果尝试连接到请求的数据库失败,PDO :: __ construct()会抛出PDOException.”
但是,如果我关闭数据库服务器并运行脚本,我得到的是一个警告:
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
没有异常被抛出.
有没有直接的方法来捕获错误(没有临时设置自定义错误管理器功能的麻烦?)
谢谢!