0

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;    

}

誰かが最初のコードを正しく機能させる方法を知っていますか?編集:私はいくつかのコードをコメントに変更しました-しかしそれはまだ機能しません...

よろしく...

4

1 に答える 1

1

関数をエスケープしないように、最後の行を値で変更します。TRUE FALSENOW()

$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');

EDIT2:このフォームを使用しても大丈夫です:

..。

$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;    

}
于 2012-06-02T12:14:27.883 に答える