Tuesday, May 23, 2017

Ambiguity in question mark for regex and prepared statement placeholder of Laravel 5.1

Working in Laravel 5.1 I need to get the data for this query :

$query = "top";
$data['rawQuery'] = "category_names REGEXP '(?<![a-zA-Z])".'{?}'.'((es)?|(s?))(?![a-zA-Z])';
 $data['bindParams'] =  [$query];
 $result = DB::table($this->table)
                    ->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())
                    ->select($selectedColumns)
                    ->get();

I am unable to put my bind param to proper position which should be like this:

 select * from product_categories where category_names REGEXP '(?<![a-zA-Z])top((es)?|(s?))(?![a-zA-Z])

Whereas I am getting this:

select * from product_categories where category_names REGEXP '(tops<![a-zA-Z]){?}((es)?|(s?))(?![a-zA-Z])

The difference is that , my query value is setting to wrong place. Please show some light on this .



via subhajit

Advertisement