示例#1
0
 public static function testConf($host, $port, $database, $user, $pass)
 {
     self::$_username = $user;
     self::$_password = $pass;
     self::$_database = $database;
     self::$_hostname = $host;
     self::$_port = $port;
     self::$_loadConfig = false;
     // prevent config from being loaded, used for testing database connection
     try {
         $db = new DbConfig();
     } catch (Exception $ex) {
         self::$_loadConfig = true;
         return $ex->getMessage();
     }
     self::$_loadConfig = true;
     return true;
 }
示例#2
0
 /**
  * Returns the appropriate database configuration
  * @return array
  */
 static function getConf()
 {
     if (($url = getenv("DATABASE_URL")) !== false) {
         // dokku / heroku
         $url = parse_url($url);
         self::$_username = $url['user'];
         self::$_password = $url['pass'];
         self::$_database = substr($url["path"], 1);
         self::$_hostname = $url['host'];
         self::$_port = $url["port"];
     } else {
         if (file_exists($_SERVER['DOCUMENT_ROOT'] . $_SERVER['APP_ROOT'] . 'library/wpos/dbconfig.php')) {
             // config set
             require $_SERVER['DOCUMENT_ROOT'] . $_SERVER['APP_ROOT'] . 'library/wpos/dbconfig.php';
             self::$_username = $dbConfig['user'];
             self::$_password = $dbConfig['pass'];
             self::$_database = $dbConfig["database"];
             self::$_hostname = $dbConfig['host'];
             self::$_port = $dbConfig["port"];
         }
     }
     $conf = ["host" => self::$_hostname, "port" => self::$_port, "user" => self::$_username, "pass" => self::$_password, "db" => self::$_database];
     return $conf;
 }