DB::disconnect() allows easy disconnecting from mysql

This commit is contained in:
Sergey Tsalkov
2013-03-19 12:02:47 -07:00
parent ce11e65070
commit e94f75fe2a
2 changed files with 15 additions and 1 deletions

View File

@@ -59,6 +59,7 @@ class DB {
}
public static function get() { $args = func_get_args(); return call_user_func_array(array(DB::getMDB(), 'get'), $args); }
public static function disconnect() { $args = func_get_args(); return call_user_func_array(array(DB::getMDB(), 'disconnect'), $args); }
public static function query() { $args = func_get_args(); return call_user_func_array(array(DB::getMDB(), 'query'), $args); }
public static function queryFirstRow() { $args = func_get_args(); return call_user_func_array(array(DB::getMDB(), 'queryFirstRow'), $args); }
public static function queryOneRow() { $args = func_get_args(); return call_user_func_array(array(DB::getMDB(), 'queryOneRow'), $args); }
@@ -153,7 +154,7 @@ class MeekroDB {
public function get() {
$mysql = $this->internal_mysql;
if ($mysql == null) {
if (!($mysql instanceof MySQLi)) {
if (! $this->port) $this->port = ini_get('mysqli.default_port');
$this->current_db = $this->dbName;
$mysql = new mysqli($this->host, $this->user, $this->password, $this->dbName, $this->port);
@@ -170,6 +171,15 @@ class MeekroDB {
return $mysql;
}
public function disconnect() {
$mysqli = $this->internal_mysql;
if ($mysqli instanceof MySQLi) {
if ($thread_id = $mysqli->thread_id) $mysqli->kill($thread_id);
$mysqli->close();
}
$this->internal_mysql = null;
}
public function nonSQLError($message) {
if ($this->throw_exception_on_nonsql_error) {
$e = new MeekroDBException($message);