0

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 ...

1 Answer 1

1

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;    

}
Sign up to request clarification or add additional context in comments.

5 Comments

well if i change tHe line to the code above and use "if($this->db->count_all_results('mb_login_attempts') >= 3) { ..." it still does't work ?!
Please edit your post and add the count_all_results line. In addition, count_all_results is not equal to select * like in your other queries. It is equal to COUNT (*)
please add the code var_dump($this->db->last_query()); after the line if($this->db->count_all_results('mb_login_attempts') >= 3) and post here the result.
string(...) "SELECT COUNT(*) AS numrows FROM (mb_login_attempts) WHERE ip_adress_hash = 'e80a1a342e3540ef0e1...' AND DATE_ADD(attempt_date,INTERVAL 30 MINUTE) > 'NOW()'" ... the hash is edited
I have edited my post. Please run the new query. I have made a mistake: add FALSE instead of TRUE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.