Categories > TinyButStrong general >

Multiple DB connections with TbsSQL2

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Joris
Date: 2007-06-13
Time: 12:08

Multiple DB connections with TbsSQL2

Hi All,

I want to have 2 connections at the same time to different servers.
To test what I want i made the following testscript:

2 databases:
database a (contains table test1)
database aa (contains table test2)

login info is the same.

<?php
include_once('classes/tbssql_mysql.php');

$db_a = new clsTbsSQL('localhost','root','','a');
$db_a->Mode=3;
$db_aa = new clsTbsSQL('localhost','root','','aa');
$db_aa->Mode=3;


$row_a=$db_a->GetRow('select * from test1');

$row_aa=$db_aa->GetRow('select * from test2');
?>

The result of this code is:
[TbsSql] Trace SQL: select * from test1
[TbsSql] Database error message: Table 'aa.test1' doesn't exist
[TbsSql] Trace SQL: select * from test2

The first query performed is performed on the wrong connection, yet I selected the right one...? Is there a way to fix this problem?
By: Joris
Date: 2007-06-13
Time: 13:05

Re: Multiple DB connections with TbsSQL2

OK... I am a bit further...

It appears if more than 1 connection is opened with the same connection specs the resource id is shared.

As I was testing with 2 databases on the same server that was the problem.

I will now move 1 test database to another server and then see what happens...
By: Joris
Date: 2007-06-13
Time: 13:20

Re: Multiple DB connections with TbsSQL2

And that was the solution!

If a DB is on the same hostname, the resourceid will be shared.

Even if usernames are different it appeared.

In my case: i was using localhost as host twice and that caused the problem. If I use one localhost and one 127.0.0.1:3306 then the problem is gone


Strange things... But it was not a bug in TbsSQL! it is just the way it works.