Try to create non-existing database during setup (#3010)
authorMatthias Schmidt <gravatronics@live.com>
Mon, 19 Aug 2019 15:59:25 +0000 (17:59 +0200)
committerGitHub <noreply@github.com>
Mon, 19 Aug 2019 15:59:25 +0000 (17:59 +0200)
Close #2979

wcfsetup/install/files/lib/system/WCFSetup.class.php

index 1dabcf811d57dabc91b37b141939a956f63b32c2..f7fde95befea4d0c7208c42853f292f9c03c050d 100644 (file)
@@ -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