Question

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.

Was it helpful?

Solution

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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top