Skip to content

Commit

Permalink
fix: set pdo err mode silent
Browse files Browse the repository at this point in the history
PDO error mode is silent as a default value before php8, I force it there to override the new php8 mode that is PDO Exception
  • Loading branch information
pifou25 committed May 31, 2024
1 parent dfa1785 commit 7bee232
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/class/DB.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ class DB {

private static function initConnection() {
global $CONFIG;
$_options = [
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci',
PDO::ATTR_PERSISTENT => true,
// silent mode, default for php7: https://www.php.net/manual/fr/pdo.error-handling.php
// exception mode for debug
PDO::ATTR_ERRMODE => (DEBUG ? PDO::ERRMODE_EXCEPTION : PDO::ERRMODE_SILENT),
];
if (isset($CONFIG['db']['unix_socket'])) {
static::$connection = new PDO('mysql:unix_socket=' . $CONFIG['db']['unix_socket'] . ';dbname=' . $CONFIG['db']['dbname'], $CONFIG['db']['username'], $CONFIG['db']['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci', PDO::ATTR_PERSISTENT => true));
static::$connection = new PDO('mysql:unix_socket=' . $CONFIG['db']['unix_socket'] . ';dbname=' . $CONFIG['db']['dbname'],
$CONFIG['db']['username'], $CONFIG['db']['password'], $_options);
} else {
static::$connection = new PDO('mysql:host=' . $CONFIG['db']['host'] . ';port=' . $CONFIG['db']['port'] . ';dbname=' . $CONFIG['db']['dbname'], $CONFIG['db']['username'], $CONFIG['db']['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci', PDO::ATTR_PERSISTENT => true));
static::$connection = new PDO('mysql:host=' . $CONFIG['db']['host'] . ';port=' . $CONFIG['db']['port'] . ';dbname=' . $CONFIG['db']['dbname'],
$CONFIG['db']['username'], $CONFIG['db']['password'], $_options);
}
}

Expand Down

0 comments on commit 7bee232

Please sign in to comment.