Jump to content

[SOLVED] How Can we use more than one Data Base Access in One Page


binumathew

Recommended Posts

Sure.

 

//create connection to database1
$connection1 = new mysqli("server1","user1","password1","database1");

//create connection to database2
$connection2 = new mysqli("server2","user2","password2","database2");

//this is the query we want to send to databases
$sql = "SELECT * FROM table1";

//query database1
$result1 = $connection1->query($sql);

//query database2
$result2 = $connection2->query($sql);

Then check the manual for mysql (although be aware, that mysqli should be used for MySQL 4.1 and higher).

 

If you need to send two or more queries within one connection... just do it! ;)

 

$sql1 = "SELECT * FROM table1";

$result1 = $connection->query($sql1);

$sql2 = "SELECT * FROM table2";

$result2 = $connection->query($sql2);

Yes... once you open the connection, you can use it to send as many queries as you wish (or as many as MySQL server permits you).

 

mysqli is recommended for MySQL 4.1 and up. You can still use the 'old' mysql extension, but mysqli gives you several important advantages. Read this excellent article

 

http://www.charlesrowe.com/2007/06/15/the-four-major-benefits-of-mysqli/

 

 

Aww... man!... It was such a good article... I hope it's just a server problem and the article will be available soon...

 

Anyway, there even is a tool for automated conversion from mysql to mysqli

http://forge.mysql.com/wiki/Converting_to_MySQLi

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.