From 7bee23200b9144589f5e0589ac18f536839cf817 Mon Sep 17 00:00:00 2001 From: pifou25 Date: Sat, 1 Jun 2024 00:36:34 +0200 Subject: [PATCH] fix: set pdo err mode silent 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 --- core/class/DB.class.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/class/DB.class.php b/core/class/DB.class.php index 83b7979179..4cd5a96487 100644 --- a/core/class/DB.class.php +++ b/core/class/DB.class.php @@ -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); } }