Which version of Laravel are you learning ? 5.6 ?
May 18, 2022
6
Level 4
how to prevent sql injection with DB::select(DB::raw($query))
I thought that if I use something like this
$myQuery = "SELECT * FROM myTable where id = :id";
DB::select(DB::raw($myQuery), ['id' => $id]);
this will use my raw sql query and the 2nd array param is where I declare the variables that should be escaped to prevent sql injection, but I'm seeing in version 5.6 this isn't the case. I'm not sure if I'm using it in correctly. Anyone have some suggestions for me? my objective is to prevent sql injection while passing user input to raw queries through query builder. Appreciate any help with this one, ty.
Please or to participate in this conversation.