[BUGFIX] Replace SHOW DATABASE by query to schema 95/23795/2
authorAlexander Opitz <opitz.alexander@googlemail.com>
Thu, 5 Sep 2013 12:55:47 +0000 (14:55 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 12 Sep 2013 18:28:41 +0000 (20:28 +0200)
The SQL query "SHOW DATABASE" may be restricted on the SQL Server.
Since MySQL 5.0 (which is minimum since TYPO3 CMS 4.7) we can also query
the information_schema table to gather the information to which table
we have access.

Resolves: #47744
Releases: 6.2, 6.1
Change-Id: Ie65abadeed54cbc54bee401bdc1aab18ffc8eea6
Reviewed-on: https://review.typo3.org/23795
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/core/Classes/Database/DatabaseConnection.php

index 71032d4..108cb00 100644 (file)
@@ -1290,17 +1290,24 @@ class DatabaseConnection {
                        $this->connectDB();
                }
                $dbArr = array();
-               $db_list = $this->link->query("SHOW DATABASES");
-               while ($row = $db_list->fetch_object()) {
-                       try {
-                               $this->setDatabaseName($row->Database);
-                               if ($this->sql_select_db()) {
-                                       $dbArr[] = $row->Database;
+               $db_list = $this->link->query("SELECT SCHEMA_NAME FROM information_schema.SCHEMATA");
+               if ($db_list === FALSE) {
+                       throw new \RuntimeException(
+                               'MySQL Error: Cannot get tablenames: "' . $this->sql_error() . '"!',
+                               1378457171
+                       );
+               } else {
+                       while ($row = $db_list->fetch_object()) {
+                               try {
+                                       $this->setDatabaseName($row->SCHEMA_NAME);
+                                       if ($this->sql_select_db()) {
+                                               $dbArr[] = $row->SCHEMA_NAME;
+                                       }
+                               } catch (\RuntimeException $exception) {
+                                       // The exception happens if we cannot connect to the database
+                                       // (usually due to missing permissions). This is ok here.
+                                       // We catch the exception, skip the database and continue.
                                }
-                       } catch (\RuntimeException $exception) {
-                               // The exception happens if we cannot connect to the database
-                               // (usually due to missing permissions). This is ok here.
-                               // We catch the exception, skip the database and continue.
                        }
                }
                return $dbArr;