title: How to handle too many database connection in PHP without an increase to max connections?
body: <p>There is a file called <code>function.php</code> and I am calling it into all my website's pages with <code>require_once</code>. This file contains more than hundred functions. </p>
  
  <p>I get <code>max_user_connections</code> error from <code>mysqli_connect()</code> and right after that </p>
  
  <pre>mysqli_query() expects parameter 1 to be mysqli, boolean given</pre>
  
  <p>error shown when there are too many visitors or search engine bots are crawling fast.</p>
  
  <p>The function file is like this:</p>
  
  <pre><code>&lt;?php 
  function db_connect(){
      $link=mysqli_connect("host","dbuser","dbpass","dbname");
      if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
      mysqli_query($link,"set names 'utf8'");
  }
  
  db_connect();
  
  function func_1(){
      $result=mysqli_query($link,"select * from ...");
      ...
  }
  
  function func_2(){
      $result=mysqli_query($link,"select * from ...");
      ...
  }
  
  .
  .
  .
  
  function func_100(){
      $result=mysqli_query($link,"select * from ...");
      ...
  }
  ?&gt;
  </code></pre>
  
  <p>In the end I close the database connection. As I have checked max connection per user for my database is 50 and host provider will not change it (It's enough, they said). </p>
  
  <p>So, generally how can I handle this problem ?  (simple PHP or OOP) </p>