有人知道为什么LIKE部分在Laravel 4中不起作用吗?
$a = DB::select('select *,
day(WN_DATE) WN_DAYOFMONTH,
month(WN_DATE) WN_MONTH,
year(WN_DATE) WN_YEAR
from mytable
where year(WN_DATE)
like %?%
order by WN_DATE DESC',
array($_SESSION['filterOn']));
使用like ?
时,这是有效的,但是当我添加%
时,就像在like %?%
中那样,它就不再起作用了。
答案 0 :(得分:4)
您错放了%%运算符,请注意下面的差异 - 它们不应该放在?
占位符旁边,而应放在内部:
$query = "select *, day(WN_DATE) WN_DAYOFMONTH, month(WN_DATE) WN_MONTH, year(WN_DATE) WN_YEAR from mytable where year(WN_DATE) like ? order by WN_DATE DESC";
$param = '%'.$_SESSION['filterOn'].'%';
$result = DB::select($query , array($param));