CakePHP Reconnect to DB

2019-02-25 10:32发布

I have a script that inserts an object into the database and then I have like 20 000 other little objects to be inserted. So I save the other objects into an array and save them afterwards.

But the server sais "MySQL Server has gone away"

Can I reconnect in some way to the database? Or can I disconnect after inserting the big object and after collecting all the small object to reconnect?

1条回答
神经病院院长
2楼-- · 2019-02-25 11:11

You can in your model.

$this->ModelName->getDatasource()->disconnect(); 
    //do stuff
$this->ModelName->getDatasource()->connect(); 
查看更多
登录 后发表回答