title: PDOException: SQLSTATE[08004] [1040] Too many connections
body: <p>I'm having an issue with my database; I've been running a site for the past half year and it has been running fine since now, as it's been outputting an error when visiting it:</p>
  
  <blockquote>
    <p>Database failed to connect: PDOException: SQLSTATE[08004] [1040] Too
    many connections in dbconfig.php:14</p>
  </blockquote>
  
  <p>I've researched this quite a while but couldn't find a single solution to what may be causing this issue, as it's quite strange how it's popping up after half a year.</p>
  
  <p>My connection code is like this:</p>
  
  <pre><code>class Database {
      private $host = "localhost";
      private $db_name = "[...]";
      private $username = "[...]";
      private $password = "[...]";
  
      public $conn;
  
      public function dbConnection() {
          $this-&gt;conn = null; 
  
          try {
              $this-&gt;conn = new PDO("mysql:host=" . $this-&gt;host . ";dbname=" . $this-&gt;db_name, $this-&gt;username, $this-&gt;password);
              $this-&gt;conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);   
          } catch(PDOException $exception) {
              exit('Database failed to connect: ' . $exception);
          }
  
          return $this-&gt;conn;
      }
  }
  </code></pre>
  
  <p>What could the issue be? I'm using this code for other sites aswell, so I hope these sites won't be having the same error soon.</p>