我在使用codeigniter连接这两个数据库时遇到问题,我使用mysql进行了尝试,并且有效。
有人可以将其转换为codeigniter
这是我的代码
SELECT DATE_FORMAT(FROM_UNIXTIME(ex.extime), '%Y-%m-%d') as `export_report`, u.username as `Username`, ex.qdesc as `Search_Performed`,
ex.to as `Number_of_records_exported`, ex.format as `Format`
FROM cone.users u
INNER JOIN igdata.export_status as ex
ON u.id = ex.uid
WHERE DATE_FORMAT(FROM_UNIXTIME(ex.extime), '%Y-%m-%d') = '{$dateToday}'
ORDER BY u.username ASC
我也把它放在我的构造函数中
private $cone_read;
private $ixdata;
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->cone_read = $this->load->database('cone_read', TRUE);
$this->ixdata = $this->load->database('cone_us', TRUE);
}
最佳答案
尝试这个:
$this->db->select("DATE_FORMAT(FROM_UNIXTIME(ex.extime), '%Y-%m-%d') as export_report, u.username as Username, ex.qdesc as Search_Performed, ex.to as Number_of_records_exported, ex.format as Format");
$this->db->from('cone.users u');
$this->db->join('igdata.export_status as ex', 'u.id = ex.uid');
$this->db->where("DATE_FORMAT(FROM_UNIXTIME(ex.extime), '%Y-%m-%d') = '$dateToday'");
$this->db->order_by("u.username", "asc");
$query = $this->db->get();
关于php - 如何在Codeigniter中的两个数据库之间联接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42030545/