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

I have simple part of code:

$r=Input::get('r');
$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

This site uses Akismet to reduce spam. Learn how your comment data is processed.