-5

I want to know the syntax to join two databases in join query in CodeIgniter. I am not getting the way to join two databases. Please share if anyone has an idea.

tRuEsAtM
  • 3,517
  • 6
  • 43
  • 83
heema
  • 29
  • 1
  • 6
  • http://stackoverflow.com/questions/14159618/join-query-of-two-databases-in-codeigniter please check this url – Shibon Feb 21 '17 at 05:47
  • 3
    Possible duplicate of [Join query of two databases in codeigniter](http://stackoverflow.com/questions/14159618/join-query-of-two-databases-in-codeigniter) – NID Feb 21 '17 at 05:48

1 Answers1

0

first of all add 2nd database setting with you project/config/database.php file

$db['default'] = array(
'dsn'   => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'db1',
    'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE);



$db['defaultdb'] = array(
'dsn'   => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
    'database' => 'dcz',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE);

then add this code start of your code

    $db1 = $this->load->database('defaultdb',TRUE);

    $queryfromDB1 = $this->db->get('Table_name')->result();

    $queryfromDB2 = $db1->get('Table_name')->result();