MDL-25910 add support for custom mysql socket location
authorPetr Skoda <commits@skodak.org>
Fri, 14 Jan 2011 09:20:04 +0000 (10:20 +0100)
committerPetr Skoda <commits@skodak.org>
Fri, 14 Jan 2011 09:20:04 +0000 (10:20 +0100)
lib/dml/mysqli_native_moodle_database.php

index d4cb065..b22ca09 100644 (file)
@@ -264,15 +264,21 @@ class mysqli_native_moodle_database extends moodle_database {
         }
 
         $this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
         }
 
         $this->store_settings($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
-        unset($this->dboptions['dbsocket']);
 
 
+        // dbsocket is used ONLY if host is NULL or 'localhost',
+        // you can not disable it because it is always tried if dbhost is 'localhost'
+        if (!empty($this->dboptions['dbsocket']) and strpos($this->dboptions['dbsocket'], '/') !== false) {
+            $dbsocket = $this->dboptions['dbsocket'];
+        } else {
+            $dbsocket = ini_get('mysqli.default_socket');
+        }
         if (empty($this->dboptions['dbport'])) {
             $dbport = ini_get('mysqli.default_port');
         } else {
             $dbport = (int)$this->dboptions['dbport'];
         }
         ob_start();
         if (empty($this->dboptions['dbport'])) {
             $dbport = ini_get('mysqli.default_port');
         } else {
             $dbport = (int)$this->dboptions['dbport'];
         }
         ob_start();
-        $this->mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport);
+        $this->mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbsocket);
         $dberr = ob_get_contents();
         ob_end_clean();
         $errorno = @$this->mysqli->connect_errno;
         $dberr = ob_get_contents();
         ob_end_clean();
         $errorno = @$this->mysqli->connect_errno;