This is the basic setup of my Connector Class
where specific driver is loaded:
Code: Select all
<?php
class db {
// Constructor not used
private function __construct(){
}
// Connect database driver $dbtype to one database $dbname
public static function connect(){
require_once('db_config.php');
$dbtype = isset($dbtype) ? trim($dbtype) : '';
$dbhost = isset($dbhost) ? trim($dbhost) : '';
$dbuser = isset($dbuser) ? trim($dbuser) : '';
$dbpass = isset($dbpass) ? trim($dbpass) : '';
$dbname = isset($dbname) ? trim($dbname) : '';
$dbmode = isset($dbmode) ? trim($dbmode) : '';
$dbport = isset($dbport) ? trim($dbport) : '';
$dbfile = isset($dbfile) ? trim($dbfile) : '';
$lib = 'db_lib/';
// Prepare for connect of db drivers
switch($dbtype){
case 'mysql':
if($dbport){
$dbhost = ($dbport==3306) ? $dbhost : $dbhost.':'.$dbport;
}
require_once($lib.'db_mysql_test.php');
$db = new db_mysql($dbhost,$dbuser,$dbpass,$dbname);
break;
case 'mysqli':
$dbport = ($dbport==3306) ? null : (int)$dbport;
require_once($lib.'db_mysqli.php');
$db = new db_mysqli($dbhost,$dbuser,$dbpass,$dbname,$dbport);
break;
case 'sqlite':
require_once($lib.'db_sqlite.php');
$db = new db_sqlite($dbfile);
break;
case 'mssql':
if($dbport){
$dbhost = ($dbport==1433) ? $dbhost : $dbhost.','.$dbport;
}
require_once($lib.'db_mssql.php');
$db = new db_mssql($dbhost,$dbuser,$dbpass,$dbname);
break;
case 'pgsql':
require_once($lib.'db_pgsql.php');
$db = new db_pgsql($dbhost,$dbuser,$dbpass,$dbname,$dbport);
break;
case 'oci8':
require_once($lib.'db_oci8.php');
$db = new db_oci8($dbhost,$dbuser,$dbpass,$dbname,$dbport);
break;
case 'ibm_db2':
require_once($lib.'db_ibm_db2.php');
$db = new db_ibm_db2($dbhost,$dbuser,$dbpass,$dbname,$dbport);
break;
default:
exit('Error: Invalid config value: $dbtype ');
break;
}
return $db; // Database driver handle
} // end connect()
} // end class
?>[code]
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:4990, old post ID:38666[/size][/color]
... i make php ... i make it good