diff options
author | Paul Arthur <flowerysong00@yahoo.com> | 2012-11-08 14:28:27 -0500 |
---|---|---|
committer | Paul Arthur <flowerysong00@yahoo.com> | 2012-11-08 14:31:53 -0500 |
commit | 649298b24109c72ce664c744f4c7895d93bf987d (patch) | |
tree | bdf1d0891df5c706f0ca7037d2ca53ce60432adf | |
parent | c51ddbd3d64e92209bf4fc214bf80d8cc33cc2af (diff) | |
download | ampache-649298b24109c72ce664c744f4c7895d93bf987d.tar.gz ampache-649298b24109c72ce664c744f4c7895d93bf987d.tar.bz2 ampache-649298b24109c72ce664c744f4c7895d93bf987d.zip |
Clean up remaining direct calls to mysql functions
This makes it theoretically possible to replace Dba with a different
implementation somewhat painlessly.
-rw-r--r-- | lib/class/dba.class.php | 32 | ||||
-rw-r--r-- | lib/install.lib.php | 39 | ||||
-rw-r--r-- | templates/show_install_check.inc.php | 2 |
3 files changed, 32 insertions, 41 deletions
diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php index bec7cc00..2127a6aa 100644 --- a/lib/class/dba.class.php +++ b/lib/class/dba.class.php @@ -48,7 +48,6 @@ class Dba { public static $stats = array('query'=>0); - private static $_default_db; private static $_sql; private static $config; @@ -295,6 +294,13 @@ class Dba { } // check_database + public static function check_database_exists() { + $dbh = self::_connect(); + $select = mysql_select_db(Config::get('database_name'), $dbh); + mysql_close($dbh); + return $select; + } + /** * check_database_inserted * checks to make sure that you have inserted the database @@ -318,6 +324,9 @@ class Dba { } // check_database_inserted + public static function get_client_info() { + return mysql_get_client_info(); + } /** * show_profile @@ -343,7 +352,9 @@ class Dba { */ public static function dbh($database='') { - if (!$database) { $database = self::$_default_db; } + if (!$database) { + $database = Config::get('database_name'); + } // Assign the Handle name that we are going to store $handle = 'dbh_' . $database; @@ -367,7 +378,9 @@ class Dba { */ public static function disconnect($database='') { - if (!$database) { $database = self::$_default_db; } + if (!$database) { + $database = Config::get('database_name'); + } $handle = 'dbh_' . $database; @@ -404,19 +417,6 @@ class Dba { } // error /** - * auto_init - * This is the auto init function it sets up the config class - * and also sets the default database - */ - public static function _auto_init() { - - self::$_default_db = Config::get('database_name'); - - return true; - - } // auto_init - - /** * translate_to_mysqlcharset * This translates the specified charset to a mysqlcharset, stupid ass mysql * demands that it's charset list is different! diff --git a/lib/install.lib.php b/lib/install.lib.php index fad1112c..a92c921e 100644 --- a/lib/install.lib.php +++ b/lib/install.lib.php @@ -135,43 +135,38 @@ function install_insert_db($username,$password,$hostname,$database,$dbuser=false unset($data); - /* Attempt to make DB connection */ - $dbh = Dba::dbh(); - - if (!is_resource($dbh)) { + if (!Dba::check_database()) { Error::add('general', sprintf(T_('Error: Unable to make Database Connection %s'), Dba::error())); return false; } - /* Check/Create Database as needed */ - $db_selected = @mysql_select_db($database, $dbh); + $db_exists = Dba::check_database_exists(); - if ($db_selected && $_POST['existing_db']) { + if ($db_exists && $_POST['existing_db']) { // Rien a faire, we've got the db just blow through } - elseif ($db_selected && !$_POST['overwrite_db']) { + elseif ($db_exists && !$_POST['overwrite_db']) { Error::add('general', T_('Error: Database Already exists and Overwrite not checked')); return false; } - elseif (!$db_selected) { + elseif (!$db_exists) { $sql = "CREATE DATABASE `" . Dba::escape($database) . "`"; - if (!$db_results = @mysql_query($sql, $dbh)) { + if (!Dba::write($sql)) { Error::add('general',sprintf(T_('Error: Unable to Create Database %s'), Dba::error())); return false; } - @mysql_select_db($database, $dbh); } // if db can't be selected else { $sql = "DROP DATABASE `" . Dba::escape($database) . "`"; - $db_results = @mysql_query($sql,$dbh); + Dba::write($sql); $sql = "CREATE DATABASE `" . Dba::escape($database) . "`"; - if (!$db_results = @mysql_query($sql, $dbh)) { + if (!Dba::write($sql)) { Error::add('general', sprintf(T_('Error: Unable to Create Database %s'), Dba::error())); return false; } - @mysql_select_db($database, $dbh); } // end if selected and overwrite + Dba::disconnect(); /* Check and see if we should create a user here */ if ($_POST['db_user'] == 'create_db_user' || (strlen($dbuser) AND strlen($dbpass))) { @@ -186,7 +181,7 @@ function install_insert_db($username,$password,$hostname,$database,$dbuser=false $sql = "GRANT ALL PRIVILEGES ON " . Dba::escape($database) . ".* TO " . "'" . Dba::escape($db_user) . "'@'" . Dba::escape($hostname) . "' IDENTIFIED BY '" . Dba::escape($db_pass) . "' WITH GRANT OPTION"; - if (!$db_results = @mysql_query($sql, $dbh)) { + if (!Dba::write($sql)) { Error::add('general', sprintf(T_('Error: Unable to Insert %1$s with permissions to %2$s on %3$s %4$s'), $db_user, $database, $hostname, Dba::error())); return false; } @@ -247,12 +242,12 @@ function install_create_config($web_path,$username,$password,$hostname,$database sure that they actually work! */ // Connect to the DB - if(!is_resource($dbh)) { + if(!Dba::check_database()) { Error::add('general', T_("Database Connection Failed Check Hostname, Username and Password")); return false; } - if (!@mysql_select_db($database, $dbh)) { - Error::add('general', sprintf(T_('Database Selection Failure Check Existance of %s'), $database)); + if (!Dba::check_database_exists()) { + Error::add('general', sprintf(T_('Database selection failed. Check existence of %s'), $database)); return false; } @@ -299,16 +294,12 @@ function install_create_account($username,$password,$password2) { return false; } - $dbh = Dba::dbh(); - - if (!is_resource($dbh)) { + if (!Dba::check_database()) { Error::add('general', sprintf(T_('Database Connection Failed: %s'), Dba::error())); return false; } - $db_select = @mysql_select_db(Config::get('database_name'),$dbh); - - if (!$db_select) { + if (!Dba::check_database_inserted()) { Error::add('general', sprintf(T_('Database Select Failed: %s'), Dba::error())); return false; } diff --git a/templates/show_install_check.inc.php b/templates/show_install_check.inc.php index f405aa55..05428f16 100644 --- a/templates/show_install_check.inc.php +++ b/templates/show_install_check.inc.php @@ -88,7 +88,7 @@ Error::add('install', T_('PHP MySQL Support')); } else { - echo debug_result(mysql_get_client_info(),true); + echo debug_result(Dba::get_client_info(), true); } ?> </td> |