Browse Source

Install failed in MySQLi under certain conditions (fixes #511)

Signed-off-by: Michael Eshom <[email protected]>
Michael Eshom 11 years ago
parent
commit
2828df3560
1 changed files with 7 additions and 2 deletions
  1. 7 2
      other/install.php

+ 7 - 2
other/install.php

@@ -1099,9 +1099,13 @@ function DatabasePopulation()
 
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
 		{
+			// Use the appropriate function based on the DB type
+			if ($db_type == 'mysql' || $db_type =='mysqli')
+				$db_errorno = $db_type . '_errno';
+
 			// Error 1050: Table already exists!
 			// @todo Needs to be made better!
-			if ((($db_type != 'mysql' && $db_type != 'mysqli') || mysql_errno($db_connection) === 1050) && preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
+			if ((($db_type != 'mysql' && $db_type != 'mysqli') || $db_errno($db_connection) == 1050) && preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
 			{
 				$exists[] = $match[1];
 				$incontext['sql_results']['table_dups']++;
@@ -1109,7 +1113,8 @@ function DatabasePopulation()
 			// Don't error on duplicate indexes (or duplicate operators in PostgreSQL.)
 			elseif (!preg_match('~^\s*CREATE( UNIQUE)? INDEX ([^\n\r]+?)~', $current_statement, $match) && !($db_type == 'postgresql' && preg_match('~^\s*CREATE OPERATOR (^\n\r]+?)~', $current_statement, $match)))
 			{
-				$incontext['failures'][$count] = $smcFunc['db_error']();
+				// MySQLi requires a connection object. It's optional with MySQL, Postgres and sqlite
+				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
 			}
 		}
 		else