简体   繁体   中英

Dealing with MySQL Gone Away in Zend Framework 1

I have this pseudo code:

$id = 1;
$orders = new Orders(); // extends Zend_Db_table
$order = $order->fetchOrderById($id); // $order extends Zend_Db_Table_Row_Abstract

... some long things ...

$order->value = "something";
$order->save();

And sometime the result is:

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

I found this: http://lornajane.net/posts/2011/dealing-with-mysql-gone-away-in-zend-framework

Will be this solution?

... some long things ...

$order->value = "something";
$order->getTable()->getAdapter()->getConnection();
$order->save();

Or should I do this?

... some long things ...

$order->value = "something";
$db = Zend_Registry::get('db');
$db->getConnection();
$order->save();

Or something else?

"MySQL Server has gone away" usually means the connection to the database as timed out. You typically see this in long running scripts which might have gone for a few minutes without database interaction.

Your two suggested solutions are basically the same. They both refetch the DB connection, which in Zend DB includes reconnecting if required. So either of them should solve the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM