diff options
-rw-r--r-- | installer/cli.php | 12 | ||||
-rw-r--r-- | installer/installer.php | 11 | ||||
-rw-r--r-- | installer/web.php | 8 |
3 files changed, 22 insertions, 9 deletions
diff --git a/installer/cli.php b/installer/cli.php index f736ffcb..e88293ff 100644 --- a/installer/cli.php +++ b/installer/cli.php @@ -41,10 +41,14 @@ if (!installer::connect($config)) { } else if (!installer::select_db($config)) { oops("Database {$config['dbname']} doesn't exist and can't be created. " . "Please create the database by hand."); -} else if (!installer::db_empty($config)) { - oops("Database {$config['dbname']} already has Gallery 3 tables in it. \n" . - " Please remove the Gallery 3 tables, change your prefix,\n" . - " or specify an empty database.\n"); +} else if (is_string($count = installer::db_empty($config)) || !$count) { + if (is_string($count)) { + oops($count); + } else { + oops("Database {$config['dbname']} already has Gallery 3 tables in it. \n" . + " Please remove the Gallery 3 tables, change your prefix,\n" . + " or specify an empty database.\n"); + } } else if (!installer::unpack_var()) { oops("Unable to create files inside the 'var' directory"); } else if (!installer::unpack_sql($config)) { diff --git a/installer/installer.php b/installer/installer.php index e2c60d46..57be6cc0 100644 --- a/installer/installer.php +++ b/installer/installer.php @@ -107,7 +107,7 @@ class installer { return true; } - return mysql_query("CREATE DATABASE {$config['dbname']}") && + return mysql_query("CREATE DATABASE `{$config['dbname']}`") && mysql_select_db($config["dbname"]); } @@ -122,8 +122,13 @@ class installer { } static function db_empty($config) { - $query = "SHOW TABLES IN {$config['dbname']} LIKE '{$config['prefix']}items'"; - return mysql_num_rows(mysql_query($query)) == 0; + $query = "SHOW TABLES LIKE '{$config['prefix']}items'"; + $results = mysql_query($query); + if ($results === false) { + $msg = mysql_error(); + return $msg; + } + return mysql_num_rows($results) === 0; } static function create_admin($config) { diff --git a/installer/web.php b/installer/web.php index 65233b31..90143afb 100644 --- a/installer/web.php +++ b/installer/web.php @@ -46,8 +46,12 @@ if (installer::already_installed()) { $content = render("invalid_db_version.html.php"); } else if (!installer::select_db($config)) { $content = render("missing_db.html.php"); - } else if (!installer::db_empty($config)) { - $content = render("db_not_empty.html.php"); + } else if (is_string($count = installer::db_empty($config)) || !$count) { + if (is_string($count)) { + $content = oops($count); + } else { + $content = render("db_not_empty.html.php"); + } } else if (!installer::unpack_var()) { $content = oops("Unable to create files inside the <code>var</code> directory"); } else if (!installer::unpack_sql($config)) { |