Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP Reconnect to DB

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?

like image 524
Ciprian Mocanu Avatar asked Sep 18 '25 03:09

Ciprian Mocanu


1 Answers

You can in your model.

$this->ModelName->getDatasource()->disconnect(); 
    //do stuff
$this->ModelName->getDatasource()->connect(); 
like image 188
Kyle Avatar answered Sep 19 '25 17:09

Kyle