MDL-23610 finally fixed the broken utf8 detection in mysqli driver
authorPetr Skoda <skodak@moodle.org>
Wed, 17 Nov 2010 01:58:38 +0000 (01:58 +0000)
committerPetr Skoda <skodak@moodle.org>
Wed, 17 Nov 2010 01:58:38 +0000 (01:58 +0000)
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

index 6437518..3309002 100644 (file)
@@ -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;
     }
 
     /**