簡體   English   中英

使用CodeIgniter Active Record選擇Row

[英]Select Row with CodeIgniter Active Record

我想構建一個類似的查詢

SELECT username from users
 WHERE login_attempts > 3 AND last_attempt_time < 24 (hours).

我有2個問題來構建上述查詢。

  1. 我在DATETIME格式的last_attempt_time中存儲日期(2011-06-16 10:29:23)我可以直接選擇從現在起不到24小時的時間差的行嗎? (或者我必須選擇一行,然后檢查PHP的時差嗎?)

  2. 如何使用CodeIgniter Active Record編寫此查詢? (我需要使用get_where嗎?)我在他們的文檔中找不到任何相關的例子。

謝謝。

嘗試這個:

$this->db->select('username');
$this->db->from('users');
$this->db->where('login_attempts >', 3);
$this->db->where('last_attempt_time <', date('Y-m-d H:i:s', strtotime('-24 hours')));

$query = $this->db->get();

您可以在此處找到完整的文檔: http//codeigniter.com/user_guide/database/active_record.html#select

對Francois答案的一個小優化:

$this->db->select('username');
$this->db->where('login_attempts >', 3);
$this->db->where('last_attempt_time <', date('Y-m-d H:i:s', strtotime('-24 hours')));

$query = $this->db->get('users');

對不起,作為答案,因為評論不允許\\ n。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM