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);

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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/

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.