我在我的database.php中声明了两个数据库,我如何访问db和db2实例的用户列表
//database initialisation
$CI =& get_instance();
$CI->db1 = $CI->load->database('default', TRUE);
$CI->db2 = $CI->load->database('stylior_db', TRUE);
//select query for db2
$this->$db2->from('users');
// $this->$CI->db2->where('id',1312);
$query = $this->$CI->db2->get();
print_r($query);
if ( $query->num_rows() > 0 )
{
$row = $query->row_array();
return $row;
}
最佳答案
试试这个方法
$db_result = $this->db->get("table_users"); // here default database connected
$this->db1 = $this->load->database('db1', TRUE);
$db1_result = $this->db1->get("table_users")
关于php - 在codeigniter中获取不同数据库的select查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43276138/