我是Yii的新人,我使用findAllBySql
功能来获取一些记录。
$users = User::model()->findAllBySql("
SELECT *
FROM users u
WHERE replace(lower(u.firstname),' ','') LIKE '%:s%'
OR replace(lower(u.lastname),' ','') LIKE '%:s%'",
array(':s' => $search)
);
如果我对:s的值进行硬编码,则该函数正常工作,因此看起来Yii不会更改参数:s
。非常感谢任何帮助!
此致 泰斯
答案 0 :(得分:4)
$users = User::model()->findAllBySql("
SELECT *
FROM users u
WHERE replace(lower(u.firstname),' ','') LIKE :s
OR replace(lower(u.lastname),' ','') LIKE :s",
array(':s' => '%' . $search . '%')
);