mysqli_query(): MySQL server has gone away : <p>I'm getting these errors:</p>

<pre><code>Warning: mysqli_query(): MySQL server has gone away in (local db)

Warning: mysqli_query(): Error reading result set's header in (local db)
</code></pre>

<p>I am establishing a connection at first:</p>

<pre><code>$connection = new mysqli($server, $user, $pass, $db) or die("unable");
</code></pre>

<p>Then this:</p>

<pre><code>$sql = $connection-&gt;prepare("INSERT INTO comments (name,mail,homepage,comment,time) VALUES (?,?,?,?,?)");
$sql-&gt;bind_Param('sssss',$name,$mail,$homepage,$comment,$time);
$sql-&gt;execute();
if($sql){
  if(!addPics($connection, $image_content, $mime, $time)){
      //other code
  }
</code></pre>

<p>addPics looks like this:</p>

<pre><code>function addPics($connection, $image_content, $mime, $time){

    $sql = $connection-&gt;prepare("INSERT INTO pictures (picture, mime, time)  VALUES (?,?,?)");
    $sql-&gt;bind_Param('sss',$image_content,$mime, $time);
    $sql-&gt;execute();
    if($sql){
        return true;
    } else {
        return false;
    }
</code></pre>

<p>Error occurs at the second sql->execute. My guess is that it's because I'm using the connection for several requests but my knowledge of PHP does not allow me to figure out a solution.</p>

<p>Thank you!</p>
