PDO shows no errors

4

My connection code does not show errors, what is the problem, I searched in several places and did not find anything about it:

class Connect {

    protected static $db;

    public function __construct() {}

    public static function Database() {

        if (is_null(self::$db)) {
            try {
                self::$db = new PDO('mysql:host=' . HOSTNAME . ';dbname=' . DATABASE, USERNAME, PASSWORD);
                self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            } catch (PDOException $e) {
                die($e->getMessage());
            }
        }

        return self::$db;
    }
}
    
asked by anonymous 31.05.2017 / 16:54

1 answer

7

To display or hide errors, the parameters must be passed to PHP, if they give error in the PDO, they will be displayed. Put this code at the beginning of the file where you should see the errors:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
    
31.05.2017 / 17:09