[英]Join Query from 2 Table in 2 Different Databases in CodeIgniter
I have 2 databases needs to be joined.我有 2 个数据库需要加入。
Here is the query that I have but the $db2
is only for the 2nd database, and $this->db->query
only for 1st database.这是我的查询,但
$db2
仅适用于第二个数据库,而$this->db->query
仅适用于第一个数据库。
$akses = $db2->query("select A.uName, A.userPwd, A.[Nomor Induk], B.id_jabatan, B.nama FROM tUser A
LEFT JOIN karyawan B ON B.nik = A.[Nomor Induk]
LEFT JOIN bagian_departemen C ON C.id_bagian_dept = B.id_bagian_dept
WHERE A.uName = '$username' AND A.userPwd = '$password'"
);
I want to know the syntax to join 2 table from 2 databases.我想知道从 2 个数据库连接 2 个表的语法。
Databases:数据库:
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'helpdesk',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'striction' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$db['another_db'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'produksi',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'striction' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
try like this:试试这样:
$this->db->select("db1.table.column")
$this->db->join('db1.table', 'db1.table.column = db2.table.column');
$query = $this->db->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.