是否可以从不同的数据库加入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');
但两者都给我错误
错误号码:1096
没有使用表格
SELECT *
答案 0 :(得分:1)
在select * as
中需要table name
$this->dbsections->select("$section.*");// write tour table name before *
并删除一次
// $query = $this->dbsections->get();