From cd4f18595a18ca4363c7f7ed6ab7ad794a62efe6 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Wed, 17 Nov 2010 01:58:38 +0000 Subject: [PATCH] MDL-23610 finally fixed the broken utf8 detection in mysqli driver this was actually causing tons of false reports because people are often creating the database without the encoding parameter, especially when testing upgrades --- lib/dml/mysqli_native_moodle_database.php | 31 +++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/dml/mysqli_native_moodle_database.php b/lib/dml/mysqli_native_moodle_database.php index 643751864f7..33090022922 100644 --- a/lib/dml/mysqli_native_moodle_database.php +++ b/lib/dml/mysqli_native_moodle_database.php @@ -572,11 +572,38 @@ class mysqli_native_moodle_database extends moodle_database { $result = $this->mysqli->query($sql); $this->query_end($result); + $return = false; if ($result) { + while($row = $result->fetch_assoc()) { + if (isset($row['Value'])) { + $return = (strtoupper($row['Value']) === 'UTF8' or strtoupper($row['Value']) === 'UTF-8'); + } + break; + } $result->close(); - return true; } - return false; + + if (!$return) { + return false; + } + + $sql = "SHOW LOCAL VARIABLES LIKE 'collation_database'"; + $this->query_start($sql, null, SQL_QUERY_AUX); + $result = $this->mysqli->query($sql); + $this->query_end($result); + + $return = false; + if ($result) { + while($row = $result->fetch_assoc()) { + if (isset($row['Value'])) { + $return = (strpos($row['Value'], 'latin1') !== 0); + } + break; + } + $result->close(); + } + + return $return; } /** -- 2.43.0