Categories > TinyButStrong general >

Multiple DB connections... Help?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: joris
Date: 2007-06-09
Time: 18:35

Multiple DB connections... Help?

Hi all,

I am having problems using TBS...
I happen to have 2 DB connections to different DB's.
Using only the first one goes just fine.

After opening a second connection (and saving the resource ID) TBS uses the second DB connection, instead of the first one.

Is it possible to add the database resource ID to TBS so that it uses the right DB connection?

I keep getting these types of errors (which make sense):
TinyButStrong Error when merging block [sites] : MySql error message when opening the query: Table 'gep_testsite.sites' doesn't exist

Please let me know if I am missing something (even if its possible)

Thanks in advance!
Joris

By: Skrol29
Date: 2007-06-10
Time: 01:10

Re: Multiple DB connections... Help?

Hi,

You can use the PHP resource handler of your MySQL connection for the MergeBlock() call. Thus you can manage as many MySQL connection as you wish.

$TBS->MergeBlock('blk1',$con1,'SELECT ...');
$TBS->MergeBlock('blk2',$con2,'SELECT ...');
By: joris
Date: 2007-06-10
Time: 13:12

Re: Multiple DB connections... Help?

Sweet!

Thank you very much!
By: joris
Date: 2007-06-11
Time: 20:33

Re: Multiple DB connections... Help?

Hi,me again...

Still don't work :(

I now used tbsSql (which is great by the way!)

This works:
$TBS =& new clsTinyButStrong ;
$db = new clsTbsSQL($srv='localhost',$uid='root',$pwd='',$db='gep_testsite',$drv='');

$TBS->LoadTemplate('templates/index_login.htm');
$title='';

$TBS->MergeBlock('sites','tbssql','SELECT * FROM sites') ;

$TBS->Show();

Then, if I try to use the resource id from tbsSql it doesn't...
$TBS =& new clsTinyButStrong ;
$db = new clsTbsSQL($srv='localhost',$uid='root',$pwd='',$db='gep_testsite',$drv='');

$TBS->LoadTemplate('templates/index_login.htm');
$title='';

$TBS->MergeBlock('sites',''.$db->Id,'SELECT * FROM sites') ;

$TBS->Show();

unsupported variable type : 'boolean'.

This is because $db->Id equals 1

Trying just by using $db also doesn't work...

Data source Id 'clsTbsSql' is unsupported because function 'tbsdb_clsTbsSql_open' is not found.

Can anybody help me?



By the way:
This also doesn't work for me?

<?php
$db = new clsTbsSQL($srv='localhost',$uid='root',$pwd='',$db='gep_testsite',$drv='');
$db2 = new clsTbsSQL($srv='localhost',$uid='root',$pwd='',$db='gep_testsite2',$drv='');

echo $db->Id.' - '.$db2->Id;
?>

that should give something like this:
1 - 2

but it gives

- 1
By: Skrol29
Date: 2007-06-11
Time: 23:42

Re: Multiple DB connections... Help?

Hi,

Just try:
$TBS->MergeBlock('sites',$db->Id,'SELECT * FROM sites');
By: joris
Date: 2007-06-12
Time: 18:15

Re: Multiple DB connections... Help?

Me again...
Call me crazy... That is just what I do... But it does not work... :(

<?
$TBS =& new clsTinyButStrong ;
$db = new clsTbsSQL($srv='localhost',$uid='root',$pwd='',$db='gep_admin');

$TBS->LoadTemplate('templates/index_login.htm');
$title='';

$TBS->MergeBlock('sites',$db->Id,'SELECT * FROM sites') ;

$TBS->Show();
?>


Looking a bit further...

the output of this script is:
$db = new clsTbsSQL($srv='localhost',$uid='root',$pwd='',$db='gep_admin');

if (is_resource($db->Id))
  echo 'resource';
else
  echo 'no resource';

"no resource"



$db->Id = true

when I look in the class I see the following function:
_Dbs_Prepare()
It sets the $this->Id to true... After _Dbs_Connect had set it to the resourceID...? Why is that?

If I comment that part
function _Dbs_Prepare() {
    if (@mysql_ping()) { // Check if a MySQL connection already exist
        //$this->Id = true;
    }
}

It works fine...
By: Skrol29
Date: 2007-06-15
Time: 14:05

Re: Multiple DB connections... Help?

Hi,

Which TbsSQL are you using ?
I mean which file exactly ?
By: joris
Date: 2007-06-15
Time: 14:15

Re: Multiple DB connections... Help?

// TbsSql Engine
// Version 2.0, 2007-03-01, Skrol29

That would be this version

But I discovered that I was making 2 db connections to the same server. Then PHP uses connection pooling. Thats why it was sharing the 1 db resource id in the two connections. (Also see: www.php.net/mysql_connect and http://www.php.net/mysql_select_db)
The documentation there speaks of conection pooling

When I made 1 with "localhost" and 1 with "127.0.0.1:3306" it all worked just fine.

But I altered the class myself when it connects I add the variable $this->Resourceid... Then everything works perfect.
By: Skrol29
Date: 2007-06-16
Time: 00:11

Re: Multiple DB connections... Help?

Ok, if it works then...

But I was asking which file name because it can be "tbssql_mysql.php" or "tbssql_mysqli.php".