Codeigniter : How to join 2 tables in databases from 2 different connections -
i made 2 database connections in database.php
, 1 reading localhost machine , 1 writing "insert" online database.
but ran problem when wanted join 2 tables "answers" in localhost database , "user" in online database.
function get_users() { $write_db = $this->load->database('default', true); /* database conection localhost db */ $read_db = $this->load->database('read', true); /* database conection online db */ $read_db->select('*'); $read_db->from('ibitstore.user'); $write_db->join('english.answers','ibitstore.user.user_id = english.answers.user_id'); $query = $read_db->get(); if($query->num_rows() > 0) return $query->result_array(); return array(); }
when use $write_db
join clause
$write_db->join('english.answers','ibitstore.user.user_id = english.answers.user_id');
data retrieved online database not localhost database, ignored join tried use:
$read_db->join('english.answers','ibitstore.user.user_id = english.answers.user_id');
then got sql error. looks thought "answers" table on online db:
a database error occurred
error number: 1142
select command denied user 'user'@'49.32.197.240' table 'answers'
select * (`ibitstore`.`user`) join `english`.`answers` on `ibitstore`.`user`.`user_id` = `english`.`answers`.`user_id`
filename: c:\xampp\htdocs\english\system\database\db_driver.php
line number: 330
please :(
you have 1 connection database @ time. you'd have run query on 1 database, run query on second database , manipulate results of both within php.