gpt4 book ai didi

php - Codeigniter 加入来自 2 个数据库的表

转载 作者:行者123 更新时间:2023-11-28 23:33:08 29 4
gpt4 key购买 nike

是否可以连接来自不同数据库的 2 个表?

这是我的问题

public function getschedule($section){
$this->dbsections->select('*');
$this->dbsections->from($section);

//I want to join the column "teacher" of the "section_name" table that is in the "dbsections" database
//to the "id" column of the "teachers" table in the "dbusers" database

$this->dbsections->join('teachers', 'teachers.ID = '.$section.'.TEACHER');
$query = $this->dbsections->get();

$query = $this->dbsections->get();
return $query->result_array();
}

显然,这段代码给我错误。我也试过了

$this->dbsections->join('dbusers.teachers', 'teachers.ID = '.$section.'.TEACHER');

$this->dbsections->join('dbusers.teachers', 'teachers.ID = dbsections.'.$section.'.TEACHER');

但两者都给我错误

Error Number: 1096

No tables used

SELECT *

最佳答案

在 select * as 中需要表名

$this->dbsections->select("$section.*");// write tour table name before *

并删除一次

   //  $query = $this->dbsections->get();

关于php - Codeigniter 加入来自 2 个数据库的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36736085/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com