我对 Doctrine 很陌生,我有一个问题。我用 CodeIgniter 安装了 Doctrine 2。这是我在 CodeIgniter 中调用 Doctrine 的课程:
<?php
use Doctrine\Common\ClassLoader;
class Doctrine
{
public $conn;
public function __construct()
{
try
{
require_once APPPATH . '/third_party/Doctrine/Common/ClassLoader.php';
$classLoader = new ClassLoader('Doctrine', APPPATH . 'third_party' );
$classLoader->register();
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array(
'dbname' => 'mydb',
'user' => 'user',
'password' => 'secret',
'host' => 'localhost',
'driver' => 'pdo_mysql'
);
$this->conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
} catch (\PDOException $e){
echo 'An error as ocurred...';
} catch (Exception $ex) {
echo 'ERROR';
}
}
配置参数错误,有可能抛出异常,在本例中为PDOException
. 但令我惊讶的是,我收到了消息
“发生错误......”我得到“致命错误:未捕获的异常'PDOException',消息'SQLSTATE [HY000] [1045]用户'用户'(...)的访问被拒绝”
我尝试使用\PDOException
orPDOException
进行捕获,但无法捕获异常......
有人能帮我吗?