2012-12-21 50 views
0

根據文檔,將第三個參數'none'傳遞給類似的方法應該可以避免在類似的搜索查詢中使用通配符。CodeIgniter Active Record與第三個參數

林這樣做,其中$搜索== 'test_username':

$this->db->like('username', $search, 'none'); 
$this->db->limit(1); 
$q = $this->db->get('customers')->row(); 
var_dump($this->db->last_query());exit; 

我希望看到這顯示在屏幕上:

SELECT * FROM (`ci_customers`) WHERE `username` LIKE 'test_username' LIMIT 1 

但我不是得到這個:

SELECT * FROM (`ci_customers`) WHERE `username` LIKE '%test_username%' LIMIT 1 

這似乎是該方法忽略了第三個參數或我做錯了什麼。有任何想法嗎?我可以寫出我的查詢並使用query()方法,但我很好奇。

+0

啊,這是它應該的方式(http://ellislab.com/codeigniter/user-guide/database/active_record.html)。你正在運行什麼版本的CI? – swatkins

+0

正在運行版本2.1.0 – Rooster

回答

1

它看起來好像「無」的代碼不包含在2.1.0版本中。看看https://github.com/EllisLab/CodeIgniter/blob/v2.1.0/system/database/DB_active_rec.php#L639上的第649-692行。

,然後看看2.1.3版664線:https://github.com/EllisLab/CodeIgniter/blob/2.1.3/system/database/DB_active_rec.php#L639

你要麼需要升級,或添加到您的DB_active_rec.php文件:

... 
if ($side == 'none') 
{ 
    $like_statement = $prefix." $k $not LIKE '{$v}'"; 
} 
... 
+0

ahhhh。很好的接收。我試圖檢查覈心文件,但我找不到正確的文件。感謝您的澄清! – Rooster

+0

沒問題,它在2.1.0文檔中,但顯然從代碼中省略了。 – swatkins