add possibility to use root-mysql-connection to new database class

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-10-29 14:24:50 +01:00
parent 5d8906f1d8
commit 8172cb8fc0

View File

@@ -38,6 +38,11 @@ class Database {
*/ */
private static $_link = null ; private static $_link = null ;
/**
* indicator whether to use root-connection or not
*/
private static $_needroot = false;
/** /**
* Wrapper for PDOStatement::execute so we can catch the PDOException * Wrapper for PDOStatement::execute so we can catch the PDOException
* and display the error nicely on the panel * and display the error nicely on the panel
@@ -62,6 +67,20 @@ class Database {
return Database::query("SELECT FOUND_ROWS()")->fetchColumn(); return Database::query("SELECT FOUND_ROWS()")->fetchColumn();
} }
/**
* enabled the usage of a root-connection to the database
* Note: must be called *before* any prepare/query/etc.
* and should be called again with 'false'-parameter to resume
* the 'normal' database-connection
*
* @param bool $needroot
*/
public static function needRoot($needroot = false) {
// force re-connecting to the db with corresponding user
self::$_link = null;
self::$_needroot = $needroot;
}
/** /**
* let's us interact with the PDO-Object by using static * let's us interact with the PDO-Object by using static
* call like "Database::function()" * call like "Database::function()"
@@ -72,7 +91,7 @@ class Database {
* @return mixed * @return mixed
*/ */
public static function __callStatic($name, $args) { public static function __callStatic($name, $args) {
$callback = array(self::getDB(), $name); $callback = array(self::getDB(self::$_needroot), $name);
$result = null; $result = null;
try { try {
$result = call_user_func_array($callback, $args ); $result = call_user_func_array($callback, $args );