Codeigniter从2个数据库加入表

时间:2016-04-20 06:58:49

标签: php mysql codeigniter

是否可以从不同的数据库加入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 *

1 个答案:

答案 0 :(得分:1)

在select * as

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

并删除一次

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