aronccs aronccs - 9 months ago 19
SQL Question

Codeigniter Join tables from 2 databases

Is it possible to join 2 tables from different database?

Here is my query

public function getschedule($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');


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

But both gives me error

Error Number: 1096

No tables used



You need table name in select * as

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

And Remove one time

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