I have a very simple database structure and query. What I want is getting some rows with %like%, but it gets nothing. Here is my query:
$kslr=DB::table('kisiler')->select('*')->where('dogumgunu','%LIKE%',"29-12")->get();
When I write var_dump($kslr) it gives me an empty array.
I have three persons in kisiler table whose "dogumgunu" columns are: "29-12-1987", "29-12-1986" and "24-12-1991.
So the the query should return me 2 of these but it gets nothing, By the way the "dogumgunu" column in my table is a "text" structure whichh is set utf-8.
Thanks for your time.
Do not put wildcards in the operator, put them in the searched term!
$kslr = DB::table('kisiler')
->select('*')
->where('dogumgunu','LIKE',"%29-12%")
->get();
where('dogumgunu','%LIKE%',"29-12")
should be
where('dogumgunu','LIKE',"%29-12%")
LIKE is an operator
%29-12% is a term
If you are unable to generate the query you need via the fluent interface, feel free to use whereRaw and REGEXP :
$kslr=DB::table('kisiler')
->select('*')
->whereRaw("dogumgunu REGEXP '^[0-9]-[0-9]'")
->get();
Example;
$kslr=DB::table('kisiler')
->select('*')
->whereRaw("dogumgunu REGEXP '^29-12'")
->get();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.