Jump to content

PDOExcepction


omidh

Recommended Posts

Hi

I'm start my website three days ago but today when i browse my website i got this error :

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[00000] [1040] Too many connections' in /hermes/bosweb/web126/b1264/*/inc/Connection.class.php:20 Stack trace: #0 /hermes/bosweb/web126/b1264/*/inc/Connection.class.php(20): PDO->__construct('mysql:host=game...', '***', '***') #1 /hermes/bosweb/web126/b1264/*/inc/Connection.class.php(16): connection->stablish_connection() #2 /hermes/bosweb/web126/b1264/*/inc/init.php(6): connection->__construct() #3 /hermes/bosweb/web126/b1264/*/inc/header.php(1): include_once('/hermes/bosweb/...') #4 /hermes/bosweb/web126/b1264/*/index.php(2): include('/hermes/bosweb/...') #5 {main} thrown in /hermes/bosweb/web126/b1264/*/inc/Connection.class.php on line 20

 

MySQL Version:

    5.0.83

Perl Version:

    5.8.8

PHP Version:

    5.2.12

 

 

I'm didn't make this script and i can't find who make it, when i contact  my support, they said "we don't support PDO" but i'm wonder how it works before

this is Connection.class.php:

<?php

 

  class connection {

     

      public $cnn;

      private $hostname;

      private $DBName;

      private $username;

      private $password;

     

      function __construct() {

        $this->hostname="***.ipagemysql.com";

        $this->DBName="gm_*1";

        $this->username="gm_*2";

        $this->password="gm_*3";

        $this->stablish_connection();

      }

     

      function stablish_connection() {

        $this->cnn = new PDO("mysql:host=$this->hostname;dbname=$this->DBName", $this->username, $this->password);

        $this->cnn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

      }

     

  }

 

?>

Please help me to debug or replace this

Thanks

Link to comment
https://forums.phpfreaks.com/topic/247938-pdoexcepction/
Share on other sites

So that is about 20 connections for each page that is loaded.  If there are 20 people on the site, that is 20 * 20 = 400 connections to your database.  This is what I'm guessing the problem is.  I would change this object so that it follows the Singleton pattern so that there is ever only 1 instance in existence.

 

~juddster

Link to comment
https://forums.phpfreaks.com/topic/247938-pdoexcepction/#findComment-1273178
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.