[TYPO3-core] using t3lib_db for non-TYPO3 databases on the same host

Bernhard Kraft kraftb at kraftb.at
Thu Jul 6 15:39:37 CEST 2006

Hash: SHA1

Martin Kutschker wrote:
> Hi!
> Currently it is not possible to connect to the same db host but use another db.
> Why? typo3_db uses mysql_[p]connect() using the connection pool. So any 
> connect to the same server will get the same handle. Any further 
> select_db() will affect the main handle of $TYPO3_DB.

I didn't have any problems with the following code:

- ------------
         $GLOBALS[$name] = t3lib_div::makeInstance('t3lib_DB');
         $this->connectToDB($name, $props['hostname'], $props['username'], $props['password'], $props['database']);
- -------------

   function connectToDB($name, $host, $user, $pass, $db) {
      if ($GLOBALS[$name]->sql_pconnect($host, $user, $pass))  {
         if (!$db)   {
            return false;
         } elseif (!$GLOBALS[$name]->sql_select_db($db)) {
            return false;
         return true;
      } else {
         if (!$db)   {
            return false;
         return false;


- --------------

It worked out of the box to synchronize 2 databases using $GLOBALS['TYPO3_DB'] and $GLOBALS['MY_DB']

both were connected to different databases (sql_select_db) but on the same server .... i don't know how it acts
if both databases are on a different server.

As I would "interpret" the "persistent" of pconnect I would say that it only reopens the connnetion if you specified
the same host/database combination. I think once I tried to connect to the same database as two different users and
AFAIR this failed ... so if you choose different hosts/databases it will also work using sql_pconnect.
At least that's the experience I had.

- --
- ----------------------------------------------------------------------
"Freiheit ist immer auch die Freiheit des Andersdenkenden"
Rosa Luxemburg, 1871 - 1919
- ----------------------------------------------------------------------
[[ http://think-open.at | Open source company ]]
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org


More information about the TYPO3-team-core mailing list