function install_check_table_conflicts($database_name, $webtag, $check_forum_tables, $check_global_tables, $remove_conflicts) { // Database connection. if (!($db = db::get())) { return false; } // SQL to get a list of existing tables in the database. $sql = "SHOW TABLES FROM `{$database_name}`"; // Execute query. if (!($result = $db->query($sql))) { return false; } // Check there are some existing tables in the database. if ($result->num_rows < 1) { return false; } // Get the existing tables as an array. while ($table_data = $result->fetch_row()) { $existing_tables[] = $table_data[0]; } // Get arrays of global and forum tables. install_get_table_names($global_tables, $forum_tables); // Prefix the forum tables with the webtag array_walk($forum_tables, 'install_prefix_webtag', $webtag); // Construct the final array we'll use to check. $check_tables_array = array_merge($check_global_tables ? $global_tables : array(), $check_forum_tables ? $forum_tables : array()); // array_intersect can find our duplicates. $conflicting_tables_array = array_intersect($existing_tables, $check_tables_array); // Check if we should remove conflicts automatically. if ($remove_conflicts === true && sizeof($conflicting_tables_array) > 0) { $sql = sprintf('DROP TABLE IF EXISTS `%s`', implode('`, `', array_map(array($db, 'escape', $conflicting_tables_array)))); $db->query($sql); } // Return either the conflicting table names or false. return sizeof($conflicting_tables_array) > 0 ? $conflicting_tables_array : false; }
function install_check_table_conflicts($database_name, $webtag, $check_forum_tables, $check_global_tables, $remove_conflicts) { if (!($db = db::get())) { return false; } $sql = "SHOW TABLES FROM `{$database_name}`"; if (!($result = $db->query($sql))) { return false; } if ($result->num_rows < 1) { return false; } $existing_tables = array(); while (($table_data = $result->fetch_row()) !== null) { $existing_tables[] = $table_data[0]; } install_get_table_names($global_tables, $forum_tables); foreach ($forum_tables as $key => $forum_table) { $forum_tables[$key] = install_prefix_webtag($forum_table, $webtag); } $check_tables_array = array_merge($check_global_tables ? $global_tables : array(), $check_forum_tables ? $forum_tables : array()); $conflicting_tables_array = array_intersect($existing_tables, $check_tables_array); if ($remove_conflicts === true && sizeof($conflicting_tables_array) > 0) { $sql = sprintf('DROP TABLE IF EXISTS `%s`', implode('`, `', array_map(array($db, 'escape'), $conflicting_tables_array))); $db->query($sql); } return sizeof($conflicting_tables_array) > 0 ? $conflicting_tables_array : false; }