Compare date in where clause of manual query using parameterised query in Laravel not working
<p>I am developing a Laravel 5.2 web application. I am retrieving record from database according to user input date that is compared to timestamp in database. I am running manual query using parameterized query because the query is too complicated.</p>

<p>I retrieve records like this</p>

<pre><code>$sql = "SELECT * FROM `usres`";
$sql .= " WHERE DATE(`created_at`) = '2015-04-04'";
DB::select($sql);

$date = '2015-04-04';
$sql = "SELECT * FROM `usres`";
$sql .= " WHERE DATE(`created_at`) = '{$date}'";
DB::select($sql);
</code></pre>

<p>As you can see above, I did not use parameterized query. <code>created_at</code> is timestamp and so I converted it into date. The above query is working. It is retrieving the correct data.</p>

<p>I retrieve using parameterized query like this</p>

<pre><code>$date = '2015-04-04';
$sql = "SELECT * FROM `usres`";
$sql .= " WHERE DATE(`created_at`) = ?";
DB::select($sql,[$date]);
</code></pre>

<p>The above code is not working. As you can see, I used parameterized query. I tried like below as well.</p>

<pre><code>$date = "'".2015-04-04."'";
$sql = "SELECT * FROM `usres`";
$sql .= " WHERE DATE(`created_at`) = ?";
DB::select($sql,[$date]);


$date = "2015-04-04";
$sql = "SELECT * FROM `usres`";
$sql .= " WHERE DATE_FORMAT(`created_at`,'%Y-%m-%d') = ?";
DB::select($sql,[$date]);
</code></pre>

<p>This is not working as well.</p>

<p>Why it is not retrieving data when I use parameterized query?</p>