2012-12-21 51 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