I am getting more of too many connections error , what's the solution for that problem , this is my error
America/Chicago] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1040] Too many connections' in /aaa/bbb/public_html/fol/Database.php:10
Stack trace:
#0 /aaa/bbb/public_html/fol/Database.php:10: PDO->__construct('mysql:host=loca...', 'aaaaa', 'aaa@20gdhh315', Array)
As Mureinik said and without knowing your code , try to empty object (close connection) :
$mbd = new PDO('mysql:host=localhost;dbname=prueba', $usuario, $contraseña);
$mbd = null;
Its good idea to use singelton for dealing with some concurrence for example :
<?php
class Dba
{
private $bdd = null;
private static $_instance;
private function __construct()
{
$this->bdd = new PDO('mysql:dbname=test;host=localhost','root','');
}
public static function connexion()
{
if(is_null(self::$_instance))
{
self::$_instance = new Dba();
}
return self::$_instance;
}
}
?>
By this way you're checking if you have a previous instace of your Dba class and if not then you will create..
Hope i helped!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.