I am running a Cron Job for a PHP script in Codeigniter to convert uploaded videos. Everything executes without any problems, but once it gets to inserting the data into the database I receive this error:
Error Number: 2006 MySQL server has gone away
The process basically converts the video, if that was successful create the thumbnail and poster from the video and then insert the video data into the database. I have tried adding $this->db->reconnect();
in my model function. Here is the function:
function add_video($data)
{
//BECASUE THE CONVERSION TAKES SO LONG WE NEED TO RECONNECT TO THE DATABASE AFTER EACH EXEC
$this->db->reconnect();
$this->db->insert('video_uploads', $data);
}
This did not work I still recieved the error. If I add $this->db->reconnect();
after each exec
I receive these errors:
Message: mysql_ping() expects parameter 1 to be resource, boolean given
Message: mysql_real_escape_string() expects parameter 2 to be resource, boolean given
Just as an FYI I am using FFMPEG to convert my videos.
How can I keep the connection alive after all of the executions have finished so I can insert the data into the database?
EDIT: here is what Codeigniter's $this->db->reconnect();
functions looks like:
public function reconnect()
{
if (mysql_ping($this->conn_id) === FALSE)
{
$this->conn_id = FALSE;
}
}