MDL-26290 make sure ini_get('mysqli.default_port') returns number
authorPetr Skoda <commits@skodak.org>
Sun, 6 Feb 2011 20:15:40 +0000 (21:15 +0100)
committerPetr Skoda <commits@skodak.org>
Sun, 6 Feb 2011 20:21:23 +0000 (21:21 +0100)
lib/dml/mysqli_native_moodle_database.php

index b22ca09..450e57a 100644 (file)
@@ -57,10 +57,14 @@ class mysqli_native_moodle_database extends moodle_database {
         }
 
         if (empty($this->dboptions['dbport'])) {
-            $dbport = ini_get('mysqli.default_port');
+            $dbport = (int)ini_get('mysqli.default_port');
         } else {
             $dbport = (int)$this->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
         $dberr = ob_get_contents();
@@ -273,10 +277,14 @@ class mysqli_native_moodle_database extends moodle_database {
             $dbsocket = ini_get('mysqli.default_socket');
         }
         if (empty($this->dboptions['dbport'])) {
-            $dbport = ini_get('mysqli.default_port');
+            $dbport = (int)ini_get('mysqli.default_port');
         } else {
             $dbport = (int)$this->dboptions['dbport'];
         }
+        // verify ini.get does not return nonsense
+        if (empty($dbport)) {
+            $dbport = 3306;
+        }
         ob_start();
         $this->mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbsocket);
         $dberr = ob_get_contents();