我试图通过启用持久数据库连接来提高volkszaehler.org实现的性能。攻击已包含Doctrine的Connection
课程以PDO::ATTR_PERSISTENT => true
,我收到了PDO错误General error: PDO::ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances"
有什么方法可以解决这个问题吗?
答案 0 :(得分:16)
您可以将自己的PDO实例传递给Doctrine,自己设置持久连接:
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass, array(
PDO::ATTR_PERSISTENT => true
));
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array(
'dbname' => 'mydb',
'user' => 'user',
'password' => 'secret',
'host' => 'localhost',
'pdo' => $dbh,
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
请务必了解与PDO使用持久连接的含义:What are the disadvantages of using persistent connection in PDO