From 631a7883ee355e5c01160eb5559f3912b4c604f8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 19 Jan 2009 00:14:28 +0000 Subject: Get rid of the driver libaries. Use mysql calls directly in the installer for now. If we detect mysqli, we can always use that as a driver instead, but we don't require it for the installer. --- installer/index.php | 1 - installer/installer.php | 37 ++++-------- installer/libraries/Install_Mysql_Driver.php | 79 ------------------------ installer/libraries/Install_Mysqli_Driver.php | 86 --------------------------- 4 files changed, 10 insertions(+), 193 deletions(-) delete mode 100644 installer/libraries/Install_Mysql_Driver.php delete mode 100644 installer/libraries/Install_Mysqli_Driver.php (limited to 'installer') diff --git a/installer/index.php b/installer/index.php index da17147a..7999a76a 100644 --- a/installer/index.php +++ b/installer/index.php @@ -24,7 +24,6 @@ * -u Database user (default: root) * -p Database user password (default: ) * -d Database name (default: gallery3) - * -i Database type (default: mysqli) * -t Table prefix (default: ) * -m Modules to install (default: core, user) * -f Response file (default: not used) diff --git a/installer/installer.php b/installer/installer.php index ea01f799..403f4260 100644 --- a/installer/installer.php +++ b/installer/installer.php @@ -272,14 +272,6 @@ class installer { self::$config = array_merge($config, $arguments); foreach (self::$config as $key => $value) { - if ($key == "type") { - $value = ucfirst(self::$config["type"]); - self::$config[$key] = $value; - $class = "Install_{$value}_Driver"; - if (!class_exists($class)) { - require_once(DOCROOT . "installer/libraries/$class" . EXT); - } - } if ($key == "modules") { $value = implode(", ", array_keys($value)); } @@ -292,39 +284,31 @@ class installer { $section = array("header" => "Database Configuration", "description" => "Gallery3 requires the following database configuration.", "msgs" => array()); - $class = self::$config["type"]; - $class = "Install_{$class}_Driver"; - self::$database = - new $class(self::$config["host"], self::$config["user"], self::$config["password"]); + if (!mysql_connect(self::$config["host"], self::$config["user"], self::$config["password"])) { + throw new Exception(mysql_error()); + } /* * If we got this far, then the user/password combination is valid and we can now * a little more information for the individual that is running the script. We can also * connect to the database and ask for more information */ - $databases = self::$database->list_dbs(); - $dbname = self::$config["dbname"]; + $db_config_valid = true; - if (empty($databases[$dbname])) { + if (!mysql_select_db(self::$config["dbname"]) && !mysql_create_db(self::$config["dbname"])) { $db_config_valid = false; - $section["msgs"]["Database"] = array("text" => "Database '$dbname' is not defined", - "error" => true); - } else { - $section["msgs"]["Database"] = array("text" => "Database '$dbname' is defined", - "error" => false); + $section["msgs"]["Database"] = array( + "text" => "Database '$dbname' is not defined and can't be created", + "error" => true); } - $tables = self::$database->list_tables(self::$config["dbname"]); - - $valid = count($tables) == 0; - if (!$valid) { + if (mysql_num_rows(mysql_query("SHOW TABLES FROM " . self::$config["dbname"]))) { $db_config_valid = false; $section["msgs"]["Database Empty"] = array("text" => "Database '$dbname' is not empty", - "error" => true); + "error" => true); } self::$messages[] = $section; - return $db_config_valid; } @@ -363,7 +347,6 @@ class installer { "prefix" => self::$config["prefix"]); $config = self::_render("installer/views/database.php", $data); - printf("
%s
",print_r($db_config_file,1));flush(); if (file_put_contents($db_config_file, $config) !== false) { print "'var/database.php' created\n"; } else { diff --git a/installer/libraries/Install_Mysql_Driver.php b/installer/libraries/Install_Mysql_Driver.php deleted file mode 100644 index 6ddfd1fc..00000000 --- a/installer/libraries/Install_Mysql_Driver.php +++ /dev/null @@ -1,79 +0,0 @@ -_link = @mysql_connect($server, $user, $password); - if (!$this->_link) { - throw new Exception(mysql_error()); - } - $this->_server = $server; - $this->_user = $user; - } - - public function __destruct() { - if (!empty($this->_link)) { - @mysql_close($this->_link); - } - } - - public function list_dbs() { - $db_list = mysql_list_dbs($this->_link); - $databases = array(); - while ($row = mysql_fetch_object($db_list)) { - $databases[$row->Database] = 1; - } - return $databases; - } - - public function get_access_rights($dbname) { - $select = "SELECT PRIVILEGE_TYPE " . - " FROM `information_schema`.`schema_privileges`" . - " WHERE `GRANTEE` = '\\'{$this->_user}\\'@\\'{$this->_server}\\''" . - " AND `TABLE_SCHEMA` = '$dbname';"; - $privileges = mysql_query($select, $this->_link); - $permissions = array(); - if ($privileges) { - while ($row = mysql_fetch_assoc($privileges)) { - $permissions[strtolower($row["PRIVILEGE_TYPE"])] = 1; - } - } - return $permissions; - } - - public function select_db($dbname) { - mysql_select_db($dbname); - } - - public function list_tables($dbname) { - $select = "SHOW TABLES FROM $dbname;"; - $db_tables = mysql_query($select, $this->_link); - $tables = array(); - if ($db_tables) { - while ($row = mysql_fetch_assoc($db_tables)) { - $tables[$row["Tables_in_$dbname"]] = 1; - } - } - return $tables; - } -} diff --git a/installer/libraries/Install_Mysqli_Driver.php b/installer/libraries/Install_Mysqli_Driver.php deleted file mode 100644 index 9eaaf1fc..00000000 --- a/installer/libraries/Install_Mysqli_Driver.php +++ /dev/null @@ -1,86 +0,0 @@ -_mysqli = @mysqli_connect($server, $user, $password); - if (!$this->_mysqli) { - throw new Exception(mysqli_connect_error()); - } - $this->_server = $server; - $this->_user = $user; - } - - public function __destruct() { - if (!empty($this->_mysqli)) { - @$this->_mysqli->close(); - $this->_mysqli = null; - } - } - - public function list_dbs() { - $db_list = $this->_mysqli->query("SHOW DATABASES"); - $databases = array(); - if ($db_list) { - while ($row = $db_list->fetch_row()) { - $databases[$row[0]] = 1; - } - } - return $databases; - } - - public function get_access_rights($dbname) { - $select = "SELECT PRIVILEGE_TYPE " . - " FROM `information_schema`.`schema_privileges`" . - " WHERE `GRANTEE` = '\\'{$this->_user}\\'@\\'{$this->_server}\\''" . - " AND `TABLE_SCHEMA` = '$dbname';"; - print $select; - $privileges = $this->_mysqli->query($select); - $permissions = array(); - if ($privileges) { - while ($row = $privileges->fetch_row()) { - $permissions[strtolower($row[0])] = 1; - } - } - return $permissions; - } - - public function select_db($dbname) { - $this->_mysqli->select_db($dbname); - } - - public function list_tables($dbname) { - $select = "SHOW TABLES FROM $dbname;"; - $db_tables = $this->_mysqli->query($select); - $tables = array(); - if ($db_tables) { - while ($row = $db_tables->fetch_row()) { - $tables[strtolower($row[0])] = 1; - } - } - return $tables; - } -} - -- cgit v1.2.3