PDO shows no errors

Asked

Viewed 291 times

4

My connection code shows no errors, what’s the problem, I searched several places and found nothing 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;
    }
}

1 answer

5


To display or hide errors, the parameters must be passed to PHP, so if there is an error in the PDO lib, they will be displayed. Place this code at the beginning of the file that should be able to see the errors:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
  • Now it has appeared, grateful...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.