我尝试在单个php文件中连接两个数据库,并尝试通过连接两个数据库的表来检索数据。这是我的代码
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查询未运行。 college_db和mini-project是两个数据库。
答案 0 :(得分:0)
尝试
$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 ";
答案 1 :(得分:0)
如果这样做?不行吗?
$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);