Check on error number rather than error message

This commit is contained in:
Alexander Nell 2020-05-19 13:45:42 +02:00
parent 85435c1b4b
commit 64e136e9e4

View File

@ -98,10 +98,11 @@ class GameModeSettings implements ConfiguratorMenu, CallbackListener, Communicat
$renameQuery = "ALTER TABLE `" . self::TABLE_SCRIPT_SETTINGS . "` RENAME TO `" . self::TABLE_GAMEMODE_SETTINGS . "`;"; $renameQuery = "ALTER TABLE `" . self::TABLE_SCRIPT_SETTINGS . "` RENAME TO `" . self::TABLE_GAMEMODE_SETTINGS . "`;";
$result = $mysqli->query($renameQuery); $result = $mysqli->query($renameQuery);
var_dump($mysqli);
if (!$result) { if (!$result) {
if (strpos($mysqli->error, "doesn't exist") !== false) { if ($mysqli->errno === 1146) {
// old doesn't exist, good, continue to force creation // old doesn't exist, good, continue to force creation
} elseif (strpos($mysqli->error, "already exists") !== false) { } elseif ($mysqli->errno === 1050) {
// new one exists, drop the old table, get out // new one exists, drop the old table, get out
$dropQuery = "DROP TABLE `" . self::TABLE_SCRIPT_SETTINGS . "`;"; $dropQuery = "DROP TABLE `" . self::TABLE_SCRIPT_SETTINGS . "`;";
$result = $mysqli->query($dropQuery); $result = $mysqli->query($dropQuery);