我正在使用 CodeIgniter (http://codeigniter.com/),但在查询时遇到问题:
select *
from mb_login_attempts
where ip_adress_hash = ?
and DATE_ADD(attempt_date,INTERVAL 30 MINUTE) > NOW()
我想使用以下语法:
$this->db->where('ip_adress_hash', $this->encrypt->sha1($this->input->ip_address()));
$this->db->where('DATE_ADD(attempt_date,INTERVAL 30 MINUTE) >','NOW()',TRUE);
if($this->db->count_all_results('mb_login_attempts') >= 3) {
return true;
}
如果我使用此代码:
$sql = "select *
from mb_login_attempts
where ip_adress_hash = ?
and DATE_ADD(attempt_date,INTERVAL 30 MINUTE) > NOW()";
$val = $this->db->query($sql,$this->encrypt->sha1($this->input->ip_address()));
if($val->num_rows() >= 3) {
return true;
}
有谁知道我如何让第一个代码正常工作? 编辑:我已经更改了评论中的一些代码 - 但它仍然不起作用......
问候...
最佳答案
使用 TRUE
FALSE
值修改最后一行,这样它就不会转义 NOW()
功能:
$this->db->where('DATE_ADD(attempt_date,INTERVAL 30 MINUTE) >','NOW()', FALSE);
编辑: 运行此查询:
$this->db->where('ip_adress_hash', $this->encrypt->sha1($this->input->ip_address()));
$this->db->where('DATE_ADD(attempt_date,INTERVAL 30 MINUTE) >','NOW()', FALSE);
$val = $this->db->get('mb_login_attempts');
编辑2: 使用这种形式还是可以的:
...
$this->db->where('ip_adress_hash', $this->encrypt->sha1($this->input->ip_address()));
$this->db->where('DATE_ADD(attempt_date,INTERVAL 30 MINUTE) >','NOW()', FALSE);
if($this->db->count_all_results('mb_login_attempts') >= 3) {
return true;
}
关于mysql - Codeigniter SQL 查询 - DATE_ADD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10862232/