Bug #82555

Driver switches to mysqli when using postgresql

Added by RVVN no-lastname-given almost 5 years ago. Updated almost 5 years ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2017-09-25
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
8
PHP Version:
7.0
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Hi,

to deal more easily with 4-bytes UTF8 characters (like emojis), we've decided to switch to PostgreSQL.

Our database connection is configured as following in LocalConfiguration.php :

'DB' => [
        'Connections' => [
            'Default' => [
                'charset' => 'utf8',
                'dbname' => 'xxxx',
                //'driver' => 'mysqli',
                'driver' => 'pdo_pgsql',
                'host' => 'xxxx',
                'password' => 'xxxx',
                //'port' => 3306,
                'port' => 5432,
                'user' => 'xxxx',
            ],
        ],
    ],

We can log in and display content in backend.

But as we try to save a content element, or even listing extensions, an exception occurs and we can see that the DB driver is switching to mysqli. Here is a (simplified) trace when we try to access to extension manager :

typo3/sysext/core/Classes/Database/DatabaseConnection.php: $tables_result = $this->query('SHOW TABLE STATUS FROM `' . $this->databaseName . '`');

typo3/sysext/core/Classes/Database/DatabaseConnection.php: $this->connectDB();

typo3/sysext/core/Classes/Database/DatabaseConnection.php: $this->sql_pconnect();

vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php: $this->connect();

vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php: $this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions);

vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php: throw DBALException::driverException($this, $e);

Final result : Doctrine\DBAL\Driver\AbstractMySQLDriver::convertException("An exception occured in driver: MySQL server has gone away", Doctrine\DBAL\Driver\Mysqli\MysqliException)

The sql_pconnect() function contains the following code that explicitly instantiates a connection using mysqli driver :

// We are not using the TYPO3 CMS shim here as the database parameters in this class
        // are settable externally. This requires building the connection parameter array
        // just in time when establishing the connection.
        $connection = \Doctrine\DBAL\DriverManager::getConnection([
            'driver' => 'mysqli',
            'wrapperClass' => Connection::class,
            'host' => $host,
            'port' => (int)$this->databasePort,
            'unix_socket' => $this->databaseSocket,
            'user' => $this->databaseUsername,
            'password' => $this->databaseUserPassword,
            'charset' => $this->connectionCharset,
        ]);  

        // Mimic the previous behavior of returning false on connection errors
        try {
            /** @var \Doctrine\DBAL\Driver\Mysqli\MysqliConnection $mysqliConnection */
            $mysqliConnection = $connection->getWrappedConnection();
            $this->link = $mysqliConnection->getWrappedResourceHandle();
        } catch (\Doctrine\DBAL\Exception\ConnectionException $exception) {
            return false;
        }

Why is that hard coded?

Did we miss something in our PostgreSQL configuration ?

Also available in: Atom PDF