简体   繁体   English

使用多个查询合并来自两个mysql数据库的两个表

[英]using multiple queries to combine two tables from two mysql databases

Now that I know that one query will not be able to combine two tables from two different mysql databases, Is it possible to create multiple queries to display results in PHP after combining two tables from two mysql databases? 既然我知道一个查询将无法合并来自两个不同mysql数据库的两个表,是否可以在合并来自两个mysql数据库的两个表后创建多个查询以在PHP中显示结果? I have two mysql databases that have different passwords. 我有两个具有不同密码的mysql数据库。 I would like to display the results after I join two tables: one from each database. 加入两个表后,我想显示结果:每个数据库一个。 This is what I have thus far: 到目前为止,这是我所拥有的:

$connectdb1 = mysqli_connect("localhost", "dblogin1", "pswd1", "db1");
$connectdb2 = mysqli_connect("localhost", "dblogin2", "pswd2", "db2");

$sorc815sql = "SELECT * FROM db1.myaudtable LEFT JOIN db2.contacttable ON myaudtable.myAudContactID=contacttable.contactID";

$sorc815res = mysqli_query($sorc815sql);
echo '<br>$sv815res='.$sorc815res;

I do get an error, "Warning: mysqli_query() expects at least 2 parameters, 1 given in (file location) on line 31" 我确实收到错误消息,“警告:mysqli_query()至少需要2个参数,第31行的(文件位置)给定1个参数”

mysqli_query($connection,$query) expects 2 parameters. mysqli_query($connection,$query)需要2个参数。 first one is the connection string, in your case $connectdb1 or $connectdb2 and second query $sorc815sql 第一个是连接字符串,在您的情况下$connectdb1$connectdb2 ,第二个查询$sorc815sql

You can't join two tables from different database in a single query. 您不能在单个查询中连接来自不同数据库的两个表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM