views:

157

answers:

2

Hi, while executing a long script that uses Doctrine to access the db, I get an error 2006 server has gone away.

I've already solved this problem on a website that doens't use Doctrine. The solution there was to use mysqli instead of the normal mysql driver.

How can i tell Doctrine to use a mysqli-driver in order to avoid 2006-errors?

Thanks!

+1  A: 

I don't think you will be able to do this, because Doctrine uses PDO rather than the older mysqli or mysql extensions.

Tom Haigh
In that case: how can 2006-errors be avoided with PDO?
murze
@murze: does it happen when you run specific queries or does it just fail after a long time? I have had it in the past where the server's max_allowed_packet mysql setting is too low. But that wouldn't explain why it works in mysqli
Tom Haigh
@Tom Haigh: it happens when I try to execute a doctrine command after an api-call to mailchimp. The answer of the api-call takes about 50 seconds.
murze
@murze: You could try changing wait_timeout on your mysql server, e.g. run the sql: `SET GLOBAL wait_timeout=60` . Also is your PHP version up to date? i did read about some issues like this with PDO/MySQL and PHP version 5.1
Tom Haigh
My php version 5.2.12. Unfortunately I'm on shared hosting and can't change any of the globel mysql-parameters.
murze
A: 

You can try this:

$masterConn->getDbh()->setAttribute(PDO::ATTR_PERSISTENT, false);

If prepared statements are used, add this,

$masterConn->getDbh()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
ZZ Coder
Hi, i tried $conn = Doctrine_Manager::connection($dbh);$conn->getDbh()->setAttribute(PDO::ATTR_PERSISTENT, false);$conn->getDbh()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);but still got the 2006 server has gone away error :-(
murze