when an instance of MeekroDB is created, its default settings will be those of the static instance

This commit is contained in:
Sergey Tsalkov
2014-10-26 01:57:20 +00:00
parent 83256937b8
commit 1fe2fdea16

View File

@@ -41,6 +41,8 @@ class DB {
// internal // internal
protected static $mdb = null; protected static $mdb = null;
public static $variables_to_sync = array('param_char', 'escape_char', 'named_param_seperator', 'success_handler', 'error_handler', 'throw_exception_on_error',
'nonsql_error_handler', 'throw_exception_on_nonsql_error', 'nested_transactions', 'usenull', 'ssl', 'connect_options');
public static function getMDB() { public static function getMDB() {
$mdb = DB::$mdb; $mdb = DB::$mdb;
@@ -49,16 +51,8 @@ class DB {
$mdb = DB::$mdb = new MeekroDB(); $mdb = DB::$mdb = new MeekroDB();
} }
static $variables_to_sync = array('param_char', 'named_param_seperator', 'success_handler', 'error_handler', 'throw_exception_on_error', // Sync everytime because settings might have changed. It's fast.
'nonsql_error_handler', 'throw_exception_on_nonsql_error', 'nested_transactions', 'usenull', 'ssl', 'connect_options'); $mdb->sync_config();
$db_class_vars = get_class_vars('DB'); // the DB::$$var syntax only works in 5.3+
foreach ($variables_to_sync as $variable) {
if ($mdb->$variable !== $db_class_vars[$variable]) {
$mdb->$variable = $db_class_vars[$variable];
}
}
return $mdb; return $mdb;
} }
@@ -158,6 +152,19 @@ class MeekroDB {
$this->dbName = $dbName; $this->dbName = $dbName;
$this->port = $port; $this->port = $port;
$this->encoding = $encoding; $this->encoding = $encoding;
$this->sync_config();
}
// suck in config settings from static class
public function sync_config() {
$db_class_vars = get_class_vars('DB'); // the DB::$$var syntax only works in 5.3+
foreach (DB::$variables_to_sync as $variable) {
if ($this->$variable !== $db_class_vars[$variable]) {
$this->$variable = $db_class_vars[$variable];
}
}
} }
public function get() { public function get() {