title: PHP + ODBC + FreeTDS + MSSQL: Can't change TDS version
body: <p>I have PHP/ODBC/FreeTDS set up to connect my Ubuntu host to a remote MSSQL instance, which technically works. I can execute simple queries just fine. However, I can't use prepared statements; which yield the following error:</p>
  
  <blockquote>
    <p>Warning: odbc_execute(): SQL error: [unixODBC][Driver Manager]Driver
    does not support this function, SQL state IM001 in
    SQLDescribeParameter...</p>
  </blockquote>
  
  <p>I'm guessing that's because an early TDS version (4.2) is being used, which doesn't support prepared statements and other things. The trouble is, I can't seem to change the TDS version being used! I've tried all the configurations I can think of...</p>
  
  <p>Running <code>tsql -C</code> yields:</p>
  
  <pre><code>Compile-time settings (established with the "configure" script)
                              Version: freetds v0.91
               freetds.conf directory: /etc/freetds
       MS db-lib source compatibility: no
          Sybase binary compatibility: yes
                        Thread safety: yes
                        iconv library: yes
                          TDS version: 4.2
                                iODBC: no
                             unixodbc: yes
                SSPI "trusted" logins: no
                             Kerberos: yes
  </code></pre>
  
  <p>Notice "<code>TDS version: 4.2</code>", despite the following configuration.</p>
  
  <p><strong>odbc.ini</strong></p>
  
  <pre><code>[db_dsn]
  Driver      = FreeTDS
  Servername  = mssql_server
  Database    = my_database
  Description = My MSSQL database.
  Trace       = No
  </code></pre>
  
  <p><strong>odbcinst.ini</strong></p>
  
  <pre><code>[FreeTDS]
  Description     = TDS connection
  Driver          = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
  Setup           = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
  UsageCount      = 1
  FileUsage       = 1
  </code></pre>
  
  <p><strong>freetds.conf</strong></p>
  
  <pre><code>[global]
      tds version = 7.2
      text size = 64512
  
  [mssql_server]
      host = &lt;IP&gt;
      port = 1433
      tds version = 7.2
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>$connection = odbc_connect('db_dsn', $username, $password);
  $statement = odbc_prepare($connection, "INSERT INTO my_table (col1, col2) VALUES (? ?)");
  $exec = odbc_execute($statement, array($val1, $val2));
  </code></pre>
  
  <p>I've tried setting the <code>TDSVER</code> environment variable and also running <code>tsql -C --with-tdsver=7.0</code>, with no effect (not even in the <code>tsql -C</code> output). I also tried specifying a matching <code>TDS_Version</code> for the DSN in <code>odbc.ini</code> and using <code>Server</code> and <code>Port</code> in <code>odbc.ini</code> instead of <code>Servername</code> to declare that stuff in <code>freetds.conf</code>.</p>
  
  <p>None of those changes seemed to change the reported TDS version or the resulting SQL error I mentioned above. I am sure that I'm editing the correct <code>freetds.conf</code> file at <code>/etc/freetds</code>, and I know my DSN works because I can do simple <code>SELECT</code> statements, etc.</p>
  
  <p>Can anyone tell me what I'm overlooking or what I'm missing here? I'm sure it's some little thing, but I just can't see it.</p>
  
  <hr>
  
  <p><strong>Edit #1:</strong>
  Changed configured TDS version from 7.0 to 7.2.</p>
  
  <p><strong>Edit #2:</strong>
  As per Flipper's comment, I added the duplicate <code>Port</code> and <code>TDS_Version</code> info to my <code>odbc.ini</code> DSN as well as <code>freetds.conf</code> (no change):</p>
  
  <pre><code>[db_dsn]
  Driver      = FreeTDS
  Servername  = mssql_server
  Port        = 1433
  TDS_Version = 7.2
  Database    = my_database
  Description = My MSSQL database.
  Trace       = No
  </code></pre>