I have a special_number
table with a prefix column. The column contains 022
,021
etc data. I have a number 0216627363021
. How I match the column using LIKE
keyword to get the row.
$rate = Special::where('user_id',$user_id)
->where(DB::raw("prefix LIKE $number"))
->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-1)"))
->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-2)"))
->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-3)"))
->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-4)"))
->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-5)"))
->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-6)"))
->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-7)"))
->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-8)"))
->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-9)"))
->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-10)"))
->first();
but it return NULL. Where is the problem? Thank you.
SELECT * FROM users WHERE email LIKE '%'test'%'
when it executes the query on the server. – ITroubs Jan 9 '15 at 15:36foo='?'
is a string literal question mark,foo=?
is a placeholder. – Marc B Jan 9 '15 at 15:38