SQLSTATE [08004] [1040] Too many connections

-4

This is my connection class:

/ **  * Conn.class [CONNECTION]  * Abstract class of connection. Standard SingleTon.  * Returns a PDO object by the static getConn () method;  *  * @copyright (c) 2017, Horácio Pedro INFINITE CONNECTIONS  * / abstract class Conn {

private static $Host = HOST;
private static $User = USER;
private static $Pass = PASS;
private static $Dbsa = DBSA;

/** @var PDO */
private static $Connect = null;

/**
 * Conecta com o banco de dados com o pattern singleton.
 * Retorna um objeto PDO!
 */
private static function Conectar() {
    try {
        if (self::$Connect == null):
            $dsn = 'mysql:host=' . self::$Host . ';dbname=' . self::$Dbsa;
            $options = [ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
            self::$Connect = new PDO($dsn, self::$User, self::$Pass, $options);
        endif;
    } catch (PDOException $e) {
        PHPErro($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
        die;
    }

    self::$Connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return self::$Connect;
}

/** Retorna um objeto PDO Singleton Pattern. */
protected static function getConn() {
    return self::Conectar();
}

}

The site was working normally, after almost 30 days I came up with this: > SQLSTATE [08004] [1040] Too many connections

Do you have a viable solution to this type of situation? What will be the cause behind this?

    
asked by anonymous 19.06.2018 / 13:38

1 answer

0

You can review your code and try to isolate it better and subclasses, this way you will better control the call of the connections. Try not to make multiple calls in one method. If even better dividing the code the continue error you can increase the number of concurrent connections in the MySQL settings.

    
19.06.2018 / 15:50