Friday, 6 September 2013

How do you connect to multiple MySQL databases on a single PHP page?

How do you connect to multiple MySQL databases on a single PHP page?

I have developing one website using PHP. I have 2 database one is
database1 and other is database2.
I want to connect both database on a single page. One database is used for
total website and another database used for section(some part of this
page).
My code just like -
index.php
<?php
$con1=mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("database1",$con1);
?>
//Here is some html design and php code
<?php
$con2=mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("database2",$con2);
?>
//database2 data retrieve successfully after that when i can't access
database1 and retrieve the data
//I want to fetch here data from database1.
Both two databases connected successfully.
But problem is when i connect second database the first database database1
automatic connection closed. How to fetch data from first database and
store Please help me how to fix this problem.

No comments:

Post a Comment