Commit 5e575589 authored by mcramer's avatar mcramer
Browse files

Changed the way external db connections are configured (added prefix option to db class)

parent e68cd24e
......@@ -47,16 +47,17 @@ class db extends mysqli
public $show_error_messages = true; // false in server, true in interface
// constructor
public function __construct() {
public function __construct($prefix = '') {
global $conf;
$this->dbHost = $conf['db_host'];
$this->dbName = $conf['db_database'];
$this->dbUser = $conf['db_user'];
$this->dbPass = $conf['db_password'];
$this->dbCharset = $conf['db_charset'];
$this->dbNewLink = $conf['db_new_link'];
$this->dbClientFlags = $conf['db_client_flags'];
parent::__construct($conf['db_host'], $conf['db_user'],$conf['db_password'],$conf['db_database']);
if($prefix != '') $prefix .= '_';
$this->dbHost = $conf[$prefix.'db_host'];
$this->dbName = $conf[$prefix.'db_database'];
$this->dbUser = $conf[$prefix.'db_user'];
$this->dbPass = $conf[$prefix.'db_password'];
$this->dbCharset = $conf[$prefix.'db_charset'];
$this->dbNewLink = $conf[$prefix.'db_new_link'];
$this->dbClientFlags = $conf[$prefix.'db_client_flags'];
parent::__construct($conf[$prefix.'db_host'], $conf[$prefix.'db_user'],$conf[$prefix.'db_password'],$conf[$prefix.'db_database']);
if ($this->connect_error) {
$this->updateError('DB::__construct');
return false;
......
......@@ -56,19 +56,22 @@ if(isset($_POST['start']) && $_POST['start'] == 1) {
$msg .= 'Connecting to external database...<br />';
//* Backup DB login details
$conf_bak['db_host'] = $conf['db_host'];
/*$conf_bak['db_host'] = $conf['db_host'];
$conf_bak['db_database'] = $conf['db_database'];
$conf_bak['db_user'] = $conf['db_user'];
$conf_bak['db_password'] = $conf['db_password'];
$conf_bak['db_password'] = $conf['db_password'];*/
//* Set external Login details
$conf['db_host'] = $_POST['dbhost'];
$conf['db_database'] = $_POST['dbname'];
$conf['db_user'] = $_POST['dbuser'];
$conf['db_password'] = $_POST['dbpassword'];
$conf['imp_db_host'] = $_POST['dbhost'];
$conf['imp_db_database'] = $_POST['dbname'];
$conf['imp_db_user'] = $_POST['dbuser'];
$conf['imp_db_password'] = $_POST['dbpassword'];
$conf['imp_db_charset'] = $conf['db_charset'];
$conf['imp_db_new_link'] = $conf['db_new_link'];
$conf['imp_db_client_flags'] = $conf['db_client_flags'];
//* create new db object
$exdb = new db();
$exdb = new db('imp');
$server_id = 1;
$sys_userid = 1;
......@@ -138,10 +141,10 @@ if(isset($_POST['start']) && $_POST['start'] == 1) {
}
//* restore db login details
$conf['db_host'] = $conf_bak['db_host'];
/*$conf['db_host'] = $conf_bak['db_host'];
$conf['db_database'] = $conf_bak['db_database'];
$conf['db_user'] = $conf_bak['db_user'];
$conf['db_password'] = $conf_bak['db_password'];
$conf['db_password'] = $conf_bak['db_password'];*/
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment