Bug #17376

Persistent MySQL connections to more than one database doesn't work

Added by Oliver Hader about 14 years ago. Updated almost 13 years ago.

Should have
Database API (Doctrine DBAL)
Target version:
Start date:
Due date:
% Done:


Estimated time:
TYPO3 Version:
PHP Version:
Is Regression:
Sprint Focus:


The scenario:
  • two MySQL databases used
    - t3_somedomain_de: _DEFAUL with TYPO3 stuff
    - ext_somedomain_de: externalDB with non-TYPO3 stuff (no uid, pid on tables, etc.)
  • php.ini with enabled persistent connections

The first (persitent) connection works without any problems. But when a query to the externalDB is executed, the old link identifier of the _DEFAUL database will be "reused" for the externalDB. The next query of the regular TYPO3 database will fail (e.g. "ext_somedomain_de.pages" doesn't exist).

The kind of configuration used in localconf.php:

$TYPO3_CONF_VARS['EXTCONF']['dbal']['handlerCfg'] = array(
'_DEFAULT' => array(
'type' => 'native',
'config' => array(
'username' => '<user>',
'password' => '<pass>',
'host' => 'localhost',
'database' => 't3_somedomain_de',
'externalDB' => array(
'type' => 'native',
'config' => array(
'username' => '<user>',
'password' => '<pass>',
'host' => 'localhost',
'database' => 'ext_somedomain_de',

$TYPO3_CONF_VARS['EXTCONF']['dbal']['table2handlerKeys'] = array(
'Sometable_First' => 'externalDB',
'Sometable_Second' => 'externalDB',
'Sometable_Third' => 'externalDB',
(issue imported from #M5774)


0005774.patch (2.14 KB) 0005774.patch Administrator Admin, 2007-06-11 19:46

Updated by Oliver Hader about 14 years ago

The attached patch only uses a persistent connection on the first connection. The second connection will use the regular mysql_connect() instead.
Additionally I fixed another small thing on executing $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] - it's not required to process this again on each new connection that isn't the _DEFAULT connection.


Updated by Martin Kutschker almost 14 years ago

Quote from the manual:

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

So I suggest you set up another Mysql user before you rid yourself of persistent connections.


Updated by Michael Stucki almost 14 years ago

I also think you should not change this behaviour and add a new mysql user instead.


Updated by Oliver Hader almost 14 years ago

You're right. I don't know why I tried to take the difficult way here...
Adding a new user is simple, solves the problem and doesn't need to change anything in the code.

Also available in: Atom PDF