Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Doctrine with persistent PDO connections?

I'm trying to improve performance on a volkszaehler.org implementation by enabling persistent DB connections. Having hacked included Doctrine's Connection class to have PDO::ATTR_PERSISTENT => true, I'm getting the PDO error General error: PDO::ATTR_STATEMENT_CLASS cannot be used with persistent PDO instances"

Is there any way to fix this?

like image 464
andig Avatar asked Apr 25 '13 14:04

andig


1 Answers

You could pass your own PDO instance to Doctrine, setting the persistent connection yourself:

$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);

Be sure to know the implications of using persistent connections with PDO: What are the disadvantages of using persistent connection in PDO

like image 55
bspellmeyer Avatar answered Sep 20 '22 10:09

bspellmeyer