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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.