Laravel select() don’t work with params when they have spaces

I have simple part of code:

$sql='SELECT * FROM `table` WHERE `name`=?';
$dis=DB::connection('old-dis')->select($sql, [$r]);

When $r don’t has spaces, everything works corretly. But when $r is for simple teddy bear Laravel show me error and doesn’t add ' ' to my text. I find next solution:

if(strpos($r,' ')) $r="'$r'";

Anyone has better way to fix it?

Source: laravel

Leave a Reply