omidh Posted September 27, 2011 Share Posted September 27, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/247938-pdoexcepction/ Share on other sites More sharing options...
awjudd Posted September 27, 2011 Share Posted September 27, 2011 How many times do you instantiate the connection object in your code? EDIT: Why did you close your other topic saying the *exact* same thing? ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/247938-pdoexcepction/#findComment-1273168 Share on other sites More sharing options...
omidh Posted September 27, 2011 Author Share Posted September 27, 2011 Edit : 19 - 20 times (Sorry that was my wrong but there are NOT exact same) Quote Link to comment https://forums.phpfreaks.com/topic/247938-pdoexcepction/#findComment-1273174 Share on other sites More sharing options...
awjudd Posted September 27, 2011 Share Posted September 27, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/247938-pdoexcepction/#findComment-1273178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.