title: PHP Codeigniter 3 MySQL server has gone away
body: <p>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:</p>
  
  <p><code>Error Number: 2006 MySQL server has gone away</code></p>
  
  <p>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 <code>$this-&gt;db-&gt;reconnect();</code> in my model function. Here is the function:</p>
  
  <pre><code>function add_video($data)
  {
    //BECASUE THE CONVERSION TAKES SO LONG WE NEED TO RECONNECT TO THE DATABASE AFTER EACH EXEC
    $this-&gt;db-&gt;reconnect(); 
  
    $this-&gt;db-&gt;insert('video_uploads', $data);
  }
  </code></pre>
  
  <p>This did not work I still recieved the error. If I add <code>$this-&gt;db-&gt;reconnect();</code> after each <code>exec</code> I receive these errors:</p>
  
  <p><code>Message:  mysql_ping() expects parameter 1 to be resource, boolean given</code></p>
  
  <p><code>Message:  mysql_real_escape_string() expects parameter 2 to be resource, boolean given</code></p>
  
  <p>Just as an FYI I am using FFMPEG to convert my videos. </p>
  
  <p>How can I keep the connection alive after all of the executions have finished so I can insert the data into the database?</p>
  
  <p>EDIT: here is what Codeigniter's <code>$this-&gt;db-&gt;reconnect();</code> functions looks like:</p>
  
  <pre><code>public function reconnect()
  {
      if (mysql_ping($this-&gt;conn_id) === FALSE)
      {
          $this-&gt;conn_id = FALSE;
      }
  }
  </code></pre>