/** * Select database driver and make connection * * @return void */ public function connect() { $this->db = get("db"); if (!file_exists("www/config/database.php")) { getException("You must rename and configure your 'config/database.php'"); } if (!self::$connection) { $port = $this->db["dbPort"] === 3306 ? "" : ":" . $this->db["dbPort"]; if ($this->db["dbPDO"]) { self::$connection = TRUE; $this->PDO = $this->db["dbPDO"]; if ($this->db["dbDriver"] === "mysql" or $this->db["dbDriver"] === "mysqli") { try { $this->Database = new PDO("mysql:host=" . $this->db["dbHost"] . $port . ";dbname=" . $this->db["dbName"], $this->db["dbUser"], $this->db["dbPwd"]); } catch (PDOException $e) { getException("Database Error: " . $e->getMessage()); } } elseif ($this->db["dbDriver"] === "pgsql") { try { $this->Database = new PDO("pgsql:host=" . $this->db["dbHost"] . " port=" . $this->db["dbPort"] . " dbname=" . $this->db["dbName"], $this->db["dbUser"], $this->db["dbPwd"]); } catch (PDOException $e) { getException("Database Error: " . $e->getMessage()); } } elseif ($this->db["dbDriver"] === "sqlite") { try { $this->Database = new PDO("sqlite:" . $this->db["dbFilename"]); } catch (PDOException $e) { getException("Database Error: " . $e->getMessage()); } } elseif ($this->db["dbDriver"] === "oracle") { try { $this->Database = new PDO("OCI:dbname=" . $this->db["dbName"] . ";charset=UTF-8", $this->db["dbUser"], $this->db["dbPwd"]); } catch (PDOException $e) { getException("Database Error: " . $e->getMessage()); } } } else { if ($this->db["dbDriver"] === "mssql") { $this->Database = $this->driver("MsSQL_Db"); self::$connection = $this->Database->connect($this->db); } elseif ($this->db["dbDriver"] === "mysql") { $this->Database = $this->driver("MySQL_Db"); self::$connection = $this->Database->connect($this->db); } elseif ($this->db["dbDriver"] === "mysqli") { $this->Database = $this->driver("MySQLi_Db"); self::$connection = $this->Database->connect($this->db); } elseif ($this->db["dbDriver"] === "pgsql") { $this->Database = $this->driver("PgSQL_Db"); self::$connection = $this->Database->connect($this->db); } elseif ($this->db["dbDriver"] === "sqlite") { $this->Database = $this->driver("SQLite_Db"); self::$connection = $this->Database->connect($this->db); } elseif ($this->db["dbDriver"] === "oracle") { $this->Database = $this->driver("Oracle_Db"); self::$connection = $this->Database->connect($this->db); } } } }
public function connect() { if (!file_exists("www/config/database.php")) { getException("You must rename and configure your 'config/database.php'"); } if (!self::$connection) { $port = DB_PORT === 3306 ? "" : ":" . DB_PORT; if (DB_PDO) { self::$connection = true; $this->PDO = DB_PDO; if (DB_DRIVER === "mysqli" or DB_DRIVER === "mysql") { try { $this->Database = new PDO("mysql:host=" . DB_HOST . $port . ";dbname=" . DB_DATABASE, DB_USER, DB_PWD); } catch (PDOException $e) { getException("Database Error: " . $e->getMessage()); } } elseif (DB_DRIVER === "pgsql") { try { $this->Database = new PDO("pgsql:host=" . DB_HOST . $port . ";dbname=" . DB_DATABASE, DB_USER, DB_PWD); } catch (PDOException $e) { getException("Database Error: " . $e->getMessage()); } } elseif (DB_DRIVER === "sqlite") { try { $this->Database = new PDO("sqlite:" . DB_SQLITE_FILENAME); } catch (PDOException $e) { getException("Database Error: " . $e->getMessage()); } } elseif (DB_DRIVER === "oracle") { try { $this->Database = new PDO("OCI:dbname=" . DB_DATABASE . ";charset=UTF-8", DB_USER, DB_PWD); } catch (PDOException $e) { getException("Database Error: " . $e->getMessage()); } } } else { if (DB_DRIVER === "mysqli") { $this->Database = $this->driver("MySQLi_Db"); self::$connection = $this->Database->connect(); } elseif (DB_DRIVER === "mysql") { $this->Database = $this->driver("MySQL_Db"); self::$connection = $this->Database->connect(); } elseif (DB_DRIVER === "pgsql") { $this->Database = $this->driver("PgSQL_Db"); self::$connection = $this->Database->connect(); } elseif (DB_DRIVER === "sqlite") { $this->Database = $this->driver("SQLite_Db"); self::$connection = $this->Database->connect(); } elseif (DB_DRIVER === "oracle") { $this->Database = $this->driver("Oracle_Db"); self::$connection = $this->Database->connect(); } elseif (DB_DRIVER === "mssql") { $this->Database = $this->driver("MsSQL_Db"); self::$connection = $this->Database->connect(); } } } }