I tried to connect two databases in single php file and tried to retrieve data by joining tables of both databases. Here is my code
require_once "connect.php";
require_once "connect_college.php";
$sql = "select * from college_db.students join mini-project.exam on students.adno=exam.adno and students.receipt=exam.receipt ";
if (!mysql_query($sql))
{
die('Error');
}
else
{
header("Location: generate.php");
exit();
}
Mysql query is not running. college_db and mini-project are the two databases.
Try like
$sql = "select college_db.students.*,mini-project.exam.* from college_db.students
join mini-project.exam
on college_db.students.adno=mini-project.exam.adno
and college_db.students.receipt=mini-project.exam.receipt ";
If to do like this? Not will work?
$link1 = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$link2 = mysql_connect('localhost2', 'mysql_user2', 'mysql_password2');
mysql_select_db('database1', $link1);
mysql_select_db('database2', $link2);
$res1=mysql_query($query1,$link1);
$res2=mysql_query($query1,$link2);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.