MDL-26307 fix dbport and dbsocket support when creating mysql database
authorPetr Skoda <commits@skodak.org>
Sat, 12 Feb 2011 19:08:49 +0000 (20:08 +0100)
committerPetr Skoda <commits@skodak.org>
Sat, 12 Feb 2011 19:08:49 +0000 (20:08 +0100)
lib/dml/mysqli_native_moodle_database.php

index c9064ad..b3c1ceb 100644 (file)
@@ -56,17 +56,23 @@ class mysqli_native_moodle_database extends moodle_database {
             throw new dml_exception('dbdriverproblem', $driverstatus);
         }
 
-        if (empty($this->dboptions['dbport'])) {
+        if (!empty($dboptions['dbsocket'])
+                and (strpos($dboptions['dbsocket'], '/') !== false or strpos($dboptions['dbsocket'], '\\') !== false)) {
+            $dbsocket = $dboptions['dbsocket'];
+        } else {
+            $dbsocket = ini_get('mysqli.default_socket');
+        }
+        if (empty($dboptions['dbport'])) {
             $dbport = (int)ini_get('mysqli.default_port');
         } else {
-            $dbport = (int)$this->dboptions['dbport'];
+            $dbport = (int)$dboptions['dbport'];
         }
         // verify ini.get does not return nonsense
         if (empty($dbport)) {
             $dbport = 3306;
         }
         ob_start();
-        $conn = new mysqli($dbhost, $dbuser, $dbpass, '', $dbport); /// Connect without db
+        $conn = new mysqli($dbhost, $dbuser, $dbpass, '', $dbport, $dbsocket); /// Connect without db
         $dberr = ob_get_contents();
         ob_end_clean();
         $errorno = @$conn->connect_errno;