문제

Does anybody know why the LIKE part is not working in 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']));

When using like ? , the this is working but when I add the %, as in like %?% then it does not work anymore.

도움이 되었습니까?

해결책

you are misplacing the % % operators, notice the difference below - they should not be put aside the ? placeholder, rather inside:

$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));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top