PHP在提交之前显示数据库调用

时间:2016-12-03 00:54:43

标签: php sql database

我正在对其他人的代码进行故障排除,我不习惯以这种方式调用数据库。它正在使用Codeigniter,而我想要的就是组装我自己的SQL调用版本,以便在phpMyAdmin中进行测试。

$this->db->select('c1.company_id, c1.name, u.first_name, u.last_name, c2.address1, c2.city, c2.prov_stat, c2.country, c1.url, u.email');
$this->db->from('company AS c1');
$this->db->join('contact AS c2', 'c1.company_id = c2.company_id', 'left');
$this->db->join('users as u', 'c1.user_id = u.id', 'left');
$this->db->where('c2.checked_by_ecole = 0');
$this->db->order_by('c1.name');

我是否可以使用现有的PHP函数来查看SQL语句在提交之前的最终格式是什么样的?

1 个答案:

答案 0 :(得分:0)

在运行查询之前,请使用get_compile_select()

$this->db->select('c1.company_id, c1.name, u.first_name, u.last_name, c2.address1, c2.city, c2.prov_stat, c2.country, c1.url, u.email');
$this->db->from('company AS c1');
$this->db->join('contact AS c2', 'c1.company_id = c2.company_id', 'left');
$this->db->join('users as u', 'c1.user_id = u.id', 'left');
$this->db->where('c2.checked_by_ecole = 0');
$this->db->order_by('c1.name');

die('<pre>'.$this->db->get_compile_select());

你可以在这里找到ci 3的get()和get_compile_select()文档;

相关问题