[freetds] Version Not Updating; Connection Not Connecting

Ben David bendavid at briarpatch.coop
Sat May 16 15:55:54 EDT 2015

Dear FreeTDS Mailing List,

Thanks for the list!  I've been reading it a lot to no avail, so I thought I would finally post.  The basic story for creating this is that we have a SQL Anywhere 12 database on the network here at work we are trying to connect to from another workstation - the plan is to utilize PHP PDO with FreeTDS/ODBC as the connector.

I installed FreeTDS to accomplish this in part, but I am having an incredibly difficult time getting it to work.  Here is my system config:

CentOS:               7
FreeTDS:              4.2 (trying to get it to use version 8.0)
PHP:                      5.4.16

The following configuration was adapted from a thread on this forum after multiple failed attempts otherwise, I thought it would be a better place to start than my other attempts:


My current freetds.conf:

  tds version = 8.0
  client charset = UTF-8
  dump file = /tmp/freetds.log
  dump file append = yes
  debug flags = 0xffff
  debug level = 10
  text size = 64512
  host =
  port = 2638
  tds version = 8.0
  client charset = UTF-8

odbc.ini (found in the /php.d/ directory, not in /etc/):


Description = mssql_tds
Driver    = mssql_tds
Server    = mssql_tds
Port    = 2638
Trace   = Yes
TraceFile = /tmp/odbc.log
TDS_Version = 8.0


# Define where to find the driver for the FreeTDS ODBC connections.

Trace   = yes
Tracefile = /tmp/odbc.log
ForceTrace  = Yes
Description = MSSQL driver
Driver64    = /usr/lib64/libtdsodbc.so
Setup64   = /usr/lib64/libtdsS.so
UsageCount  = 2
CPTimeout =
CPReuse   =

When I reboot, here is my tsql -C:

Version: freetds v0.91
freetds.conf directory: /etc
MS db-lib source compatibility: yes
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes


I don't know how it is happening, but the TDS version is not being updated, and I cannot even attempt to debug anything because there is no freetds.log file in my /tmp/ directory (or anywhere else - actually I did find one subsequently after using TSQL command line) when I run the php code (here's that code if relevant):

  try {
    $hostname = "";
    $port = 2638;
    $dbname = "dbname";
    $username = "username";
    $pw = "password";
    $dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
  } catch (PDOException $e) {
    echo "Failed to get DB handle: " . $e->getMessage() . "\n";
  $stmt = $dbh->prepare("select name from master..sysdatabases where name = db_name()");
  while ($row = $stmt->fetch()) {
  unset($dbh); unset($stmt);


If I use "$ tsql -S -U username -P password" it starts counting and does not stop.  A log file is created with this command:

2:44:23.453378 9855 (log.c:196):Starting log file for FreeTDS 0.91
  on 2015-05-16 12:44:23 with debug flags 0xffff.
12:44:23.454088 9855 (iconv.c:330):tds_iconv_open(0x237ccf0, UTF-8)
12:44:23.454422 9855 (iconv.c:187):local name for ISO-8859-1 is ISO-8859-1
12:44:23.454439 9855 (iconv.c:187):local name for UTF-8 is UTF-8
12:44:23.454451 9855 (iconv.c:187):local name for UCS-2LE is UCS-2LE
12:44:23.454462 9855 (iconv.c:187):local name for UCS-2BE is UCS-2BE
12:44:23.454473 9855 (iconv.c:349):setting up conversions for client charset "UTF-8"
12:44:23.454484 9855 (iconv.c:351):preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
12:44:23.454515 9855 (iconv.c:391):preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
12:44:23.454542 9855 (iconv.c:394):tds_iconv_open: done
12:44:23.454567 9855 (net.c:205):Connecting to port 1433 (TDS version 7.1)
12:44:23.455570 9855 (net.c:270):tds_open_socket: connect(2) returned "Operation now in progress"

My interpretation of this is it never succeeds?  I have no idea why it is using port 1433 and TDS version 7.1 when the port is declared as 2638 in the config and TDS is reading as 4.2 with the TSQL -C command.  Also, no odbc.log file was ever created.

I guess the first step would be to connect correctly with the tsql command line and then adapt the PHP to be compatible with how that connection is set up.

Any help or indications of where a good place to start getting this connection working would be incredibly helpful - I've spent weeks on trying to get it going, it's been a bit like entering a dark forest with barely any signs.

Kind Regards,
Ben David

More information about the FreeTDS mailing list