问题
I'm trying to do this query but I got an error (Malformed UTF-8 characters, possibly incorrectly encoded):
DB::table('my_table')->select(DB::raw("id"))
->whereRaw('UPPER(name)','=', $upper_name)
->pluck('id')->first();
I'm trying to add the UPPER
sql function to the query. With direct sql, the query should be:
select * from my_table
where UPPER(name) = 'HELLO'
Where $upper_name
= HELLO.
回答1:
Simpliest Way to do that. Hope will help you
DB::table('my_table')->select('id')
->where(DB::raw("UCASE(name)"), $upper_name)
->first();
UCASE - Convert the text to upper-case
回答2:
Bah... I got it:
DB::table('my_table')->select(DB::raw("id"))
->whereRaw('UPPER(name) = ?', $upper_name)
->pluck('id')->first();
来源:https://stackoverflow.com/questions/55384313/whereraw-laravel-with-variable