How to use like clause in Laravel when we are using Raw SQL ?

后端 未结 1 1176
死守一世寂寞
死守一世寂寞 2021-01-25 06:28

I\'m using Laravel raw sql query feature. And have to perform a like query. There are so many joins and checking in this code. So it\'s better to use raw SQL. Everything is work

相关标签:
1条回答
  • 2021-01-25 06:51

    Add the wildcards to your variable, not the query, and don't add the quotes. You're also not passing in the letter variable:

    $Stars = DB::select("select v.videoid,s.seriesshortname, v.videotitle, v.VideoShortName, v.VideoImagepath, v.Views,
    v.Likes, v.Dislikes, v.Rating, v.videocategory, v.lastupdated,v.videocategory,v.seriesid,v.genreid,v.studioid
    from tblvideo v, tblpornstarvideo pv,tblseries s,tblpornstar p
    where v.videoid = pv.videoid and v.seriesid = s.seriesid and
    upper(v.Active) = 'Y' and pv.psid = p.psid and pv.psid = :id and (v.site = 1 or v.site=3)
    and v.videotitle like :letter order by v.videotitle limit 6 offset :offset", ['id' => $id, 'letter'=> $letter.'%', 'offset' => $offset]);
    
    0 讨论(0)
提交回复
热议问题