Reputation: 319
i'm using CodeIgniter (http://codeigniter.com/) and have a problem with an query:
select *
from mb_login_attempts
where ip_adress_hash = ?
and DATE_ADD(attempt_date,INTERVAL 30 MINUTE) > NOW()
i would like to use the following syntax:
$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;
}
If i use this code:
$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;
}
Does anyone have an idea how i get the first code get working correct? Edit: i have change some code to the comments - but it still doesn't work ...
regards ...
Upvotes: 0
Views: 3406
Reputation: 14428
Modify the last line with the TRUE
FALSE
value so it won't escape the NOW()
function:
$this->db->where('DATE_ADD(attempt_date,INTERVAL 30 MINUTE) >','NOW()', FALSE);
EDIT: Run this query:
$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');
EDIT2: It Is still okay to use this form:
...
$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;
}
Upvotes: 1