Database connection failure: SQLSTATE [HY000] [2002] No such file or directory

0

I'm having this error in MySQL when I try to connect. Everything works perfectly when run by localhost, but when run by hosting, this happens:

SQLSTATE[HY000] [2002] No such file or directory

I changed the address, password, bank name ... All right. What could be causing this?

Connection class:

class Connection extends Config {
    private $dbhost = 'localhost';
    private $dbname = 'dev_pcel';
    private $dbuser = 'eudegani';
    private $dbpass = '8303';
    private $dbopts = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    private $dbconn = null;

    function __construct() {
        if (empty($this->dbconn)) {
            return $this->dbconn = $this->dbConnect();
        }
    }

    private function dbConnect() {
        if (!empty($this->dbhost) && !empty($this->dbname) && !empty($this->dbuser) && !empty($this->dbpass)) {
            try {
                $this->dbconn = new PDO("mysql:dbhost=" . $this->dbhost . ";dbname=" . $this->dbname . "", $this->dbuser, $this->dbpass, $this->dbopts);
                return $this->dbconn;
            } catch (PDOException $error) {
                exit('<h1>Falha na conexão com o banco de dados.</h1><h2>Detalhes da falha:</h2><pre>' . $error->getMessage() . '</pre>');
            }
        } else {
            exit('<h1>Falha na conexão com o banco de dados.</h1><h2>Dados de conexão não informados.</h2>');
        }
    }
}
    
asked by anonymous 20.12.2018 / 02:47

0 answers