コード例 #1
0
 public static function getInstance($logStream, $checkVersion = true)
 {
     if (!self::$conn) {
         global $config;
         // If we have a socket set - use it..
         if (isset($config['DB']['socket'])) {
             self::$conn = new dbConnection($config['DB']['host'], $config['DB']['user'], $config['DB']['password'], $config['DB']['schema'], $config['DB']['port'], $config['DB']['socket']);
             // If no socket setup - just use TCP settings
         } else {
             self::$conn = new dbConnection($config['DB']['host'], $config['DB']['user'], $config['DB']['password'], $config['DB']['schema'], $config['DB']['port']);
         }
         // Check for error connecting...
         // We use mysqli_connect_error and errno instead of $conn->connect_error / errno because it was broken before PHP 5.2.9 and 5.3.0
         if (mysqli_connect_error()) {
             throw new Exception('dbConnection->getInstance: ' . "Error: Can't connect to MySQL (" . mysqli_connect_errno() . ") - please check that settings in config.php are correct." . self::$conn->connect_error);
         }
     } else {
         // Test the connection -- throw it away and reconnect if it is bad.
         if (!self::$conn->ping()) {
             self::$conn = false;
             return self::getInstance($logStream, $checkVersion);
         }
     }
     self::$conn->setLogStream($logStream);
     // If this db connection getter is configged to check the version (default is to do so), then check it.
     if ($checkVersion) {
         self::$conn->checkSchemaVersion();
     }
     return self::$conn;
 }