title: "Could not connect. Too many connections" Error in MySQLi
body: <p>I have the following code</p>
  
  <pre><code>function openDBConn($params){
      $conn_mode = $params['conn_mode'];
      $db_conn = $params['db_conn'];
  
      //create connections
      if(empty($db_conn-&gt;info)) {
          $db_conn = new mysqli("localhost", $user, $password, "database");
          $db_conn-&gt;set_charset('UTF8'); 
          $mysqli_error = $db_conn-&gt;connect_error;
      }
  
      if($mysqli_error !== NULL){ 
          die('Could not connect &lt;br/&gt;'. $mysqli_error); 
      }else{ 
          return $db_conn; 
      }
  }
  
  //close db connection
  function closeDBConn( $params ){
      $db_conn = $params['db_conn'];
      $db_conn-&gt;close;
  }
  
  //used as below
  $db_conn = openDBConn();
  
  save_new_post( $post_txt, $db_conn );
  
  closeDBConn( array('db_conn'=&gt;$db_conn));
  </code></pre>
  
  <p>From time to time, I get the "Could not connect. Too many connections" error. 
  This tends to happen when I have Google bot scanning my website.</p>
  
  <p>This problem seems to have started ever since upgrading to MySQLi from MySQL.
  Is there any advice on how ensure all connections are closed?</p>
  
  <p>Thanks</p>