【发布时间】:2021-07-02 20:12:37
【问题描述】:
预期:
select robotid, number from tool where is_active = 1select * from robot_team where id = robotid( robotid from tool)foreach id(from robot_team), number(from tool) , status_za(from robot_team), status_zb(from robot_team), status_zm(from robot_team), status_qs(from robot_team)
结果:
- 无法通过邮递员显示成功
代码:
public function robotStatus()
{
$arr=[];
$robotlist = DB::table('robot_team AS u')
->Join(DB::connection('sql')->table('tool AS m'), 'u.id', '=', 'm.robotid')
->select('u.*', 'u.id AS uid', 'm.number AS mnumber')
->where('m.is_active', '=', 1)
->orderBy('u.id', 'desc')
->get();
if(count($robotlist)>0){
foreach ($robotlist as $v) {
$robot_arr = [
"id" => $v->uid,
"number" => $v->mnumber,
"FA" => $v->status_fa,
"FC" => $v->status_fc,
"FM" => $v->status_fm,
"PS" => $v->status_ps
];
$arr[]=$robot_arr;
}}
return $arr;
}
评论:
大家好,
Laravel : join two tables of different db connections
我尝试使用上面的代码进行组合,但失败了。
我已经阅读了上面的链接,但它无法达到我的目的,因为它是 mysql 中不同数据库中的两个表。
请帮我解决以上问题。
谢谢大家。
【问题讨论】:
-
您提供的链接中问题的答案是否不可能
-
但是mysql中可以有两个数据库吗?
-
可以从两个mysql数据库中查询,但是
join是不可能的 -
只要在同一个连接中,就可以从两个 MySQL 数据库中查询(通过连接)。如果连接不同,这是不可能的。
-
但是是否可以在变量或数组中选择表。然后使用 join 合并?
标签: php mysql sql database laravel