From a028f8e6af6065417ee0600714457c08193864ec Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 19 Aug 2019 17:59:25 +0200 Subject: [PATCH] Try to create non-existing database during setup (#3010) Close #2979 --- .../files/lib/system/WCFSetup.class.php | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 1dabcf811d..f7fde95bef 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -682,12 +682,26 @@ class WCFSetup extends WCF { $db = new MySQLDatabase($dbHostWithoutPort, $dbUser, $dbPassword, $dbName, $dbPort, true, !!(self::$developerMode)); } catch (DatabaseException $e) { - // work-around for older MySQL versions that don't know utf8mb4 - if ($e->getPrevious()->getCode() == 1115) { - throw new SystemException("Insufficient MySQL version. Version '5.5.35' or greater is needed."); + switch ($e->getPrevious()->getCode()) { + // try to manually create non-existing database + case 1049: + try { + $db = new MySQLDatabase($dbHostWithoutPort, $dbUser, $dbPassword, $dbName, $dbPort, true, true); + } + catch (DatabaseException $e) { + throw new SystemException("Unknown database '{$dbName}'. Please create the database manually."); + } + + break; + + // work-around for older MySQL versions that don't know utf8mb4 + case 1115: + throw new SystemException("Insufficient MySQL version. Version '5.5.35' or greater is needed."); + break; + + default: + throw $e; } - - throw $e; } // check sql version -- 2.20.1