added functions to get sql-data to Database-class, migrated backup-cron to new PDO database class, refs #1287

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-11-20 10:01:34 +01:00
parent 60ba3f9127
commit 7a45a534fc
3 changed files with 176 additions and 259 deletions

View File

@@ -53,6 +53,12 @@ class Database {
*/
private static $_dbname = null;
/**
* sql-access data
*/
private static $_needsqldata = false;
private static $_sqldata = null;
/**
* Wrapper for PDOStatement::execute so we can catch the PDOException
* and display the error nicely on the panel
@@ -119,6 +125,40 @@ class Database {
self::$_needroot = $needroot;
}
/**
* enable the temporary access to sql-access data
* note: if you want root-sqldata you need to
* call needRoot(true) first. Also, this will
* only give you the data ONCE as it disable itself
* after the first access to the data
*
* @param bool $needsql
*/
public static function needSqlData($needsql = false) {
self::$_needsqldata = $needsql;
self::$_sqldata = array();
self::$_link = null;
}
/**
* returns the sql-access data as array using indeces
* 'user', 'passwd' and 'host'. Returns false if not enabled
*
* @return array|bool
*/
public static function getSqlData() {
if (self::$_sqldata !== null
&& is_array(self::$_sqldata)
&& isset(self::$_sqldata['user'])
) {
return self::$_sqldata;
// automatically disable sql-data
self::$_sqldata = null;
self::$_needsqldata = false;
}
return false;
}
/**
* let's us interact with the PDO-Object by using static
* call like "Database::function()"
@@ -194,6 +234,15 @@ class Database {
$host = $sql["host"];
}
// save sql-access-data if needed
if (self::$_needsqldata) {
self::$_sqldata = array(
'user' => $user,
'passwd' => $password,
'host' => $host
);
}
// build up connection string
$driver = 'mysql';
$dsn = $driver.":";