Fatal PHP unknown error

0

Well, I was working on PHP and I get a message on line 69 of the current document:

  

Fatal error: in C: \ xampp \ htdocs \ test \ php_test \ app \ config \ database.php on line 69

public function Connect($host, $dbname, $user, $pass)
    {

        $this->host = htmlspecialchars($host);
        $this->dbname = htmlspecialchars($dbname);
        $this->user = htmlspecialchars($user);
        $this->pass = htmlspecialchars($pass);

        if (strlen($this->dbname) > 2 && strlen($this->dbname) < 50) {

            $this->dbname = filter_var($this->dbname, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_AMP);
        } else {

            return false; # Pendiente de excepcion
            $this->error .= 'Error en la dbname';
        }
        if (strlen($this->user) > 2 && strlen($this->user) < 50) {

            $this->user = filter_var($this->user, FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_AMP);
        } else {

            return false; # Pendiente de excepcion
            $this->error .= 'Error en el usuario';
        }
        if (!$this->error || empty($this->error)) {

            $this->conexion = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->dbname, $this->user, $this->pass); -> linea 69
            return $this->conexion;
        }
    }
    
asked by JOSE HERRADA 09.11.2018 в 05:27
source

1 answer

0

Check the possible error you have using try & catch:

try {
    $this->conexion = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->dbname, $this->user, $this->pass);
}catch(PDOException $e){
    print $e->getMessage();
}
    
answered by 09.11.2018 в 05:57