Skip to content

Commit 5e57558

Browse files
author
mcramer
committed
Changed the way external db connections are configured (added prefix option to db class)
1 parent e68cd24 commit 5e57558

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

interface/lib/classes/db_mysql.inc.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ class db extends mysqli
4747
public $show_error_messages = true; // false in server, true in interface
4848

4949
// constructor
50-
public function __construct() {
50+
public function __construct($prefix = '') {
5151
global $conf;
52-
$this->dbHost = $conf['db_host'];
53-
$this->dbName = $conf['db_database'];
54-
$this->dbUser = $conf['db_user'];
55-
$this->dbPass = $conf['db_password'];
56-
$this->dbCharset = $conf['db_charset'];
57-
$this->dbNewLink = $conf['db_new_link'];
58-
$this->dbClientFlags = $conf['db_client_flags'];
59-
parent::__construct($conf['db_host'], $conf['db_user'],$conf['db_password'],$conf['db_database']);
52+
if($prefix != '') $prefix .= '_';
53+
$this->dbHost = $conf[$prefix.'db_host'];
54+
$this->dbName = $conf[$prefix.'db_database'];
55+
$this->dbUser = $conf[$prefix.'db_user'];
56+
$this->dbPass = $conf[$prefix.'db_password'];
57+
$this->dbCharset = $conf[$prefix.'db_charset'];
58+
$this->dbNewLink = $conf[$prefix.'db_new_link'];
59+
$this->dbClientFlags = $conf[$prefix.'db_client_flags'];
60+
parent::__construct($conf[$prefix.'db_host'], $conf[$prefix.'db_user'],$conf[$prefix.'db_password'],$conf[$prefix.'db_database']);
6061
if ($this->connect_error) {
6162
$this->updateError('DB::__construct');
6263
return false;

interface/web/tools/dns_import_tupa.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,22 @@
5656
$msg .= 'Connecting to external database...<br />';
5757

5858
//* Backup DB login details
59-
$conf_bak['db_host'] = $conf['db_host'];
59+
/*$conf_bak['db_host'] = $conf['db_host'];
6060
$conf_bak['db_database'] = $conf['db_database'];
6161
$conf_bak['db_user'] = $conf['db_user'];
62-
$conf_bak['db_password'] = $conf['db_password'];
62+
$conf_bak['db_password'] = $conf['db_password'];*/
6363

6464
//* Set external Login details
65-
$conf['db_host'] = $_POST['dbhost'];
66-
$conf['db_database'] = $_POST['dbname'];
67-
$conf['db_user'] = $_POST['dbuser'];
68-
$conf['db_password'] = $_POST['dbpassword'];
65+
$conf['imp_db_host'] = $_POST['dbhost'];
66+
$conf['imp_db_database'] = $_POST['dbname'];
67+
$conf['imp_db_user'] = $_POST['dbuser'];
68+
$conf['imp_db_password'] = $_POST['dbpassword'];
69+
$conf['imp_db_charset'] = $conf['db_charset'];
70+
$conf['imp_db_new_link'] = $conf['db_new_link'];
71+
$conf['imp_db_client_flags'] = $conf['db_client_flags'];
6972

7073
//* create new db object
71-
$exdb = new db();
74+
$exdb = new db('imp');
7275

7376
$server_id = 1;
7477
$sys_userid = 1;
@@ -138,10 +141,10 @@ function addot($text) {
138141
}
139142

140143
//* restore db login details
141-
$conf['db_host'] = $conf_bak['db_host'];
144+
/*$conf['db_host'] = $conf_bak['db_host'];
142145
$conf['db_database'] = $conf_bak['db_database'];
143146
$conf['db_user'] = $conf_bak['db_user'];
144-
$conf['db_password'] = $conf_bak['db_password'];
147+
$conf['db_password'] = $conf_bak['db_password'];*/
145148

146149
}
147150

0 commit comments

Comments
 (0)