Creating DBInstance in PHP with Firebird Database
Im back! It's time to Code! Code! Code!, Let's say,......... Coding is much exciting than going to beach.... hahah, Anyway. Let's Start with the new coding technique.
CREATING DBINSTANCE in PHP with FIREBIRD DATABASE
<?php
class DBInstance{
private static $instance;
private static $engine;
private static $dbkey;
private static $database;
private static $username;
private static $password;
private static $charset;
private static $buffers;
private static $dialect;
private static $role;
private static $port;
private static $host;
private static $message;
protected function __construct() {}
protected function __clone() {}
public static function init(){
$file = parse_ini_file("DBConnect/config.ini",true);
try{
self::$database = $file[self::$dbkey]['database'];
self::$username = $file[self::$dbkey]['user'];
self::$password = $file[self::$dbkey]['password'];
self::$charset = $file[self::$dbkey]['charset'];
self::$buffers = $file[self::$dbkey]['buffer'];
self::$dialect = $file[self::$dbkey]['dialect'];
self::$role = $file[self::$dbkey]['userrole'];
self::$port = $file[self::$dbkey]['port'];
self::$host = $file[self::$dbkey]['host'];
}catch(Exception $e){
self::$message = "config.ini cannot be found.";
}
}
public static function setDBase($dbase){
self::$dbkey = $dbase;
}
public static function setDBEngine($dbengine){
self::$engine = $dbengine;
}
public static function getInstance(){
if(!self::$instance){
self::init();
if(self::$engine == "FireBird"){
self::$instance = ibase_connect
(
self::$host . "/" . self::$port . ":" . self::$database,
self::$username, self::$password, self::$charset,
self::$buffers, self::$dialect, self::$role
);
self::$message = "You are now connected to systems database.";
if(ibase_errcode()){
self::$message = "Ooops... Something went wrong, Unable to establish database connection";
}
}
if(self::$engine == "MySQL"){
self::$message = "MySql Not yet been Implemented";
}
}
return self::$instance;
}
public static function getDbError(){
return self::$message;
}
}
?>