how to working with two database in php/mysql?


Help on PHP

//connection file

//tested in php 5.3.5 & mysql 5.5.8

//make sure database username & database host are same at same place…

$host=”localhost”;
$dbnm=’db1′;
$dbunm=’root’;
$dbpass=”;
$conn=mysql_connect($host,$dbunm,$dbpass);
$db=mysql_select_db($dbnm,$conn);
//==================================================================//
$host_=”localhost”;
$dbnm_=’db2′;
$dbunm_=’root’;
$dbpass_=”;
$conn_=mysql_connect($host_,$dbunm_,$dbpass_);
mysql_select_db($dbnm_,$conn_) or die(mysql_error());

//==============   Example  =============================//

$sql=”select * from db1.test”;

$re=mysql_query($sql) or die(mysql_error());

$sql_=”select * from db2.test”;

$re_=mysql_query($sql_);

//join query between two database’s tables….

$sql=”select u.ano from db2.temp_data t INNER JOIN db1.users u ON t.uid=u.uid”;

$re=mysql_query($sql) or die(mysql_error());

//

View original post

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s