title: PHP PDO unixODBC FreeTDS SQL Server 'converting data type varchar(max) to datetime' in stored procedure
body: <p>I have been banging my head against this for a while. I have <code>Ubuntu 14.04 64bit</code> with <code>PHP 5.5.9-1ubuntu4.4 (cli)</code> and have installed <code>php5-odbc</code> via apt-get, I have also installed <code>freeTDS</code> and <code>unixODBC</code>.</p>
  
  <p>I am attempting to call a stored procedure by binding params as follows:</p>
  
  <pre><code>&lt;?php
  
  $dbh = new PDO('odbc:myDBSERVER', "username", "");
  
  $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  function writestp($dbh){
      $dbh-&gt;beginTransaction();
  
      $sql = " EXEC
       stp_Update_Job 
       :Job_ID,
       :Modify_Date
       ";
      $sth = $dbh-&gt;prepare($sql);
  
      $params = array(
          ":Job_ID"                      =&gt; 123456,
          ":Modify_Date"                 =&gt; date(DateTime::ISO8601)
      );
  
      try{
          $sth-&gt;execute($params);
      }catch(Exception $e){
          echo $e-&gt;getMessage();
      }
  
      $dbh-&gt;rollback();
  }
  
  writestp($dbh);
  
  ?&gt;
  </code></pre>
  
  <p>Which results in:</p>
  
  <p><code>SQLSTATE[42000]: Syntax error or access violation: 8114 [FreeTDS][SQL Server]Error converting data type varchar(max) to datetime. (SQLExecute[8114] at /build/buildd/php5-5.5.9+dfsg/ext/pdo_odbc/odbc_stmt.c:254)[Finished in 0.1s]</code></p>
  
  <p><strong>UPDATE</strong> This fixes it:</p>
  
  <pre><code>    $params = array(
          ":Job_ID"                      =&gt; 123456,
          ":Modify_Date"                 =&gt; date("Y-m-d\TH:i:s")
      );
  </code></pre>
  
  <p><strong>ENDUPDATE</strong>:</p>
  
  <p>My stored proc starts like this: </p>
  
  <pre><code>CREATE PROCEDURE [dbo].[stp_Update_Job]
                  @Job_ID                         int,
                  @Modify_Date                    datetime
  </code></pre>
  
  <p>Config files as follows:</p>
  
  <p><code>/etc/odbinst.ini</code></p>
  
  <pre><code>[FreeTDS]
  Description = Free TDS driver
  # Driver on Ubuntu 64 bit
  Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
  Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
  </code></pre>
  
  <p><code>/etc/odbc.ini</code></p>
  
  <pre><code># set a DSN
  [myDBSERVER] # you can now refer to this connection 
                      # by this name when connecting via odbc.
  
  # Some info about the connection
  Description = Connection to myDBSERVER
  
  # name of the odbc driver to use as specified in /etc/odbcinst.ini
  Driver      = FreeTDS
  
  # Database name to connect to
  Database    = myDBName
  
  # Server name as specified in /etc/freetds/freetds.conf
  ServerName  = myDBSERVER
  TDS_Version = 7.2
  </code></pre>
  
  <p><code>/etc/freetds/freetds.conf</code></p>
  
  <pre><code>[myDBSERVER]
      host = myDBSERVERHOST
      port = 1433
      tds version = 7.2
      client charset = UTF-8
  </code></pre>