Querying DATE in MySQL using PHP PDO
<p>I am updating my code to use PHP PDO... I came across an sql query</p>

<pre><code> $sql = "SELECT COUNT(id) AS number_of_item FROM ".$db_table_prefix."item_table 
WHERE id &gt; 0 
    AND date_visited BETWEEN 
    CAST('$start_date' AS DATE ) 
    AND CAST('$end_date' AS DATE )";
</code></pre>

<p>which i replace with this</p>

<pre><code>$this-&gt;sql = "SELECT COUNT(id) AS number_of_items FROM item_table
                      WHERE id &gt; :id AND date_visited
                      BETWEEN CAST(:start_date AS DATE )
                      AND CAST(:end_date AS DATE )";
        $this-&gt;prepare($this-&gt;sql);
        $this-&gt;bind(':id', 0);
        $this-&gt;bind(':start_date', $date_start);
        $this-&gt;bind(':end_date', $date_end);

        $this-&gt;execute();

        sizeof($this-&gt;multiple_fetch()) &gt; 0 ? $this-&gt;result_set = $this-&gt;multiple_fetch() : $this-&gt;result_set = 404;

        return $this-&gt;result_set;
</code></pre>

<p>I have entries in my database that meet all the criteria but my new code is giving this as a result</p>

<pre><code>array (size=1)   0 =&gt; 
    array (size=1)
      'number_of_items' =&gt; int 0
</code></pre>

<p>My questions, is there something i am doing wrong? Is there a better way or different way of using the </p>

<blockquote>
  <p>CAST(... AS DATE)</p>
</blockquote>

<p>in PDO?</p>

<blockquote>
  <p>UPDATE</p>
</blockquote>

<p>Here is what my bind method look like</p>

<pre><code>function bind($placeholder, $value, $type = null){
        if (is_null($type)) {
            switch (true) {
                case is_int($value):
                    $type = \PDO::PARAM_INT;
                    break;
                case is_bool($value):
                    $type = \PDO::PARAM_BOOL;
                    break;
                case is_null($value):
                    $type = \PDO::PARAM_NULL;
                    break;
                default:
                    $type = \PDO::PARAM_STR;
            }
        }
        $this-&gt;stmt-&gt;bindValue($placeholder, $value, $type);
    }
</code></pre>

<p>My $date_start and date_end values are 2016-11-01 and 2016-11-30 respectively. I have about 101 dummy entries in my db (item_table) with date_visited as 2016-11-18 </p>