aronccs
aronccs

Reputation: 294

Codeigniter Join tables from 2 databases

Is it possible to join 2 tables from different database?

Here is my query

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 code gives me error, obviously. I also tried

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

and

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

But both gives me error

Error Number: 1096

No tables used

SELECT *

Upvotes: 1

Views: 556

Answers (1)

Saty
Saty

Reputation: 22532

You need table name in select * as

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

And Remove one time

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

Upvotes: 1

Related Questions