Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

querying 2 databases using MYSQL and PHP 1

Status
Not open for further replies.

phpnewbie

Technical User
Sep 5, 2000
1
US
I am writing a PHP script in which I need to query 1 table in one database, and one table in another MySQL db. I dont know how I should write the connect statement.
 
you just have to create to connection, one for each database.

ex:
$conn=mysql_connect("database1","user","pass");
$conn2=mysql_connect("database2","user2","pass2");

then, as you need to query one databse or the other, you just use the correct connection

$res=mysql_exec($conn,"select * from table;");
if selecting in 1st DB
or
$res=mysql_exec($conn2,"select * from table;");
if selecting in 2nd DB Khaldryck
Programmer at the University of Brussel (Belgium)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top