title: Error when binding date parameter to prepared statement -- Using PHP PDO/ODBC with SQL Server
body: <p>I have a pdo connection with ODBC (v2000.86.359.00) connecting to an SQL Server (v8.00.2039 SP4 Standard Edition) database.</p>
  
  <p>This works:</p>
  
  <pre><code>$id = 486;
  $duedate = 'June 27, 2012';
  $query ="INSERT into AssetHistory (AssetID, DateDue) Values($id, $duedate);";                   
  $noParams = $db-&gt;exec($query);
  $db-&gt;query($query);
  </code></pre>
  
  <p>But if I try to use a prepared statement like this:</p>
  
  <pre><code>$sql = 'INSERT into AssetHistory 
      (AssetID, DateDue)
      Values(:id, :duedate);';                
  
  $input = array(':id'=&gt;486, ':duedate'=&gt;'June 27, 2012');
  $smt = $db-&gt;prepare($sql);
  $smt-&gt;execute($input);
  </code></pre>
  
  <p>I get this error (from $smt->errorInfo()):</p>
  
  <pre><code> "[Microsoft][ODBC Driver Manager] Function sequence error (SQLExecute[0] at ext\pdo_odbc\odbc_stmt.c:254)"
  </code></pre>
  
  <p>I've tried:
  1) Enclosing :duedate in single quotes
  2) Binding date to unix timestamp integer
  3) Binding :duedate to php DateTime object
  4) Inserting just $duedate into the sql statement before preparing</p>
  
  <p>At this point I might be stuck using the $db->query method and sanitizing inputs as best I can, but I would really appreciate any suggestions.</p>
  
  <p>Using PHP 5.38 on a Windows Server 2003 box.</p>
  
  <p><em>Updates:</em>
  I've removed some of the variables from a previous version of this question. The error message has changed, but the end result is the same.</p>
  
  <p>I've also tried manually binding the parameters like so:</p>
  
  <pre><code>$smt-&gt;bindValue(':id', 486, PDO::PARAM_INT);
  $smt-&gt;bindValue(':duedate', 'June 27, 2012', PDO::PARAM_STR);
  </code></pre>
  
  <p>Along with adding the convert function to the sql like so:</p>
  
  <pre><code>$sql = 'INSERT into AssetHistory 
     (AssetID, DateDue)
  Values(:id, convert(datetime,:duedate, 100));';
  </code></pre>
  
  <p>Which returns:
      "COUNT field incorrect or syntax error "</p>
  
  <p>And I've noticed that SQL Server doesn't really <a href="http://mysql.databases.aspfaq.com/how-do-i-convert-a-sql-server-datetime-value-to-a-unix-timestamp.html">play nice</a> with unix timestamps...</p>