From 4d4678ceb6dcbf9bb055b30bfd39f5f47fcd2156 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 May 2020 09:03:56 +0000 Subject: [PATCH 1/2] New experimental database configurations --- src/Database/Database.php | 9 +++++---- static/defaults.config.php | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 7adb88ffa8..4b39a13e68 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -135,8 +135,9 @@ class Database } $this->emulate_prepares = (bool)$this->configCache->get('database', 'emulate_prepares'); + $this->pdo_emulate_prepares = (bool)$this->configCache->get('database', 'pdo_emulate_prepares'); - if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) { + if (!$this->configCache->get('database', 'disable_pdo') && class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) { $this->driver = 'pdo'; $connect = "mysql:host=" . $server . ";dbname=" . $db; @@ -150,7 +151,7 @@ class Database try { $this->connection = @new PDO($connect, $user, $pass); - $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares); $this->connected = true; } catch (PDOException $e) { $this->connected = false; @@ -1029,7 +1030,7 @@ class Database $success = $this->e("LOCK TABLES " . DBA::buildTableString($table) . " WRITE"); if ($this->driver == 'pdo') { - $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares); } if (!$success) { @@ -1062,7 +1063,7 @@ class Database $success = $this->e("UNLOCK TABLES"); if ($this->driver == 'pdo') { - $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->pdo_emulate_prepares); $this->e("SET autocommit=1"); } else { $this->connection->autocommit(true); diff --git a/static/defaults.config.php b/static/defaults.config.php index d0725aa9bc..4ef006496d 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -45,8 +45,23 @@ return [ 'database' => '', // charset (String) - // Database connexion charset. Changing this value will likely corrupt special characters. + // Database connection charset. Changing this value will likely corrupt special characters. 'charset' => 'utf8mb4', + + // emulate_prepares (Boolean) (Experimental) + // If enabled, prepared statements will be emulated. + // In combination with MySQLi this will cast all return values to strings. + 'emulate_prepares' => false, + + // pdo_emulate_prepares (Boolean) (Experimental) + // If enabled, the builtin emulation for prepared statements is used. + // Due to limitations of that emulation (all return values are casted as strings) + // this will most likely cause issues and should not be used on production systems. + 'pdo_emulate_prepares' => false, + + // disable_pdo (Boolean) + // PDO is used by default (if available). Otherwise MySQLi will be used. + 'disable_pdo' => false, ], 'config' => [ // admin_email (Comma-separated list) From 56e363b84b1b39319248e7e7c6dc25db6040ab0f Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 May 2020 10:03:11 +0000 Subject: [PATCH 2/2] Fix tests --- tests/Util/Database/StaticDatabase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Util/Database/StaticDatabase.php b/tests/Util/Database/StaticDatabase.php index f2ed6c700e..c95b690c63 100644 --- a/tests/Util/Database/StaticDatabase.php +++ b/tests/Util/Database/StaticDatabase.php @@ -56,6 +56,8 @@ class StaticDatabase extends Database $this->driver = 'pdo'; $this->connection = self::$staticConnection; $this->connected = true; + $this->emulate_prepares = false; + $this->pdo_emulate_prepares = false; return $this->connected; }