[英]How to select more than one database tables using one query
I want to displaying the value from more than one database mysql tables.我想显示来自多个数据库 mysql 表的值。
I have code like this :我有这样的代码:
$db1 = "SELECT * FROM db1 where no='1' ";
$db2 = "SELECT * FROM db2 where no='1' ";
$db3 = "SELECT * FROM db3 where no='1' ";
and I want to use one query like this :我想使用这样的一个查询:
$sql = mysqli_query($connect, $db1);
while ($data = mysqli_fetch_array($sql))
{
bla bla bla...
}
is this possible if I used one query like that or there is any query to get example 3 database tables into one query?如果我使用这样的一个查询,或者有任何查询将示例 3 数据库表合并到一个查询中,这可能吗? Thanks.
谢谢。
Nope you can not get data from multiple tables using one sql query without performing a join on them.不,您不能使用一个 sql 查询从多个表中获取数据而不对它们执行连接。
But you can use mysqli_multi_query to execute multiple queries.但是您可以使用 mysqli_multi_query 来执行多个查询。
Please check https://www.w3schools.com/php/func_mysqli_multi_query.asp请检查https://www.w3schools.com/php/func_mysqli_multi_query.asp
I am assuming you have three different databases in the same server.我假设您在同一台服务器中有三个不同的数据库。 In this case, you can write the query in the below format Database.Schema.Table So in your case
在这种情况下,您可以按照以下格式编写查询Database.Schema.Table所以在您的情况下
$db1 = "SELECT * FROM Database.Schema.db1 where no='1' ";
$db2 = "SELECT * FROM Database.Schema.db2 where no='1' ";
$db3 = "SELECT * FROM Database.Schema.db3 where no='1' ";
Hope this is what you are looking for!希望这就是你要找的!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.