tptcat tptcat -3 years ago 199
Apache Configuration Question

Using mssql methods (FreeTDS, PHP and Apache on Mac OS X)

I have installed FreeTDS on my Mac, but I'm having some issues connecting using


First, when I run tsql -C I see that the freetds.conf directory is listed as
. I have a freetds.conf file inside this directory.

Next, if I connect like this:

$connect = mssql_connect('IP_ADDRESS', 'username', 'password');

then everything works as expected. That is, I can retrieve, update, insert data from/into whichever DB I select with

If I try to connect like this:

$connect = mssql_connect('DSN_NAME', 'username', 'password');

matches a datasource specified in my freetds.conf file then I get an error and
unable to connect to server: DSN_NAME
which tells me that PHP isn't correctly seeing the path to my freetds.conf file.

However, if before my call I add:


then everything works as expected. This tells me that my freetds.conf file is formatted correctly.

I've searched all over about how to find the path that PHP thinks the freetds.conf file is in, but I can't find that.

Lastly, there are some reasons I don't want to use the IP address directly in my connection as well as why I don't want to be forced to use the
method to specify the directory.

Any ideas?

Thank you.

Answer Source

When I installed FreeTDS I originally used MacPorts. I believe that this gave me some conflicts for where freetds.conf should have been. And even though the path for freetds.conf when running tsql -C was the actual path that I was attempting to use, when I compiled the extension with that path PHP wouldn't recognize it.

The solution is to forget MacPorts for FreeTDS and just install FreeTDS from source. Then install the extension from the PHP source and make sure you're using the same version that is on your system (mine was 5.3.13 under OS X Mountain Lion).

If you follow the instructions at this blog exactly you shouldn't have any issues.

A couple of final things:

  • I am NOT running MAMP even though the instructions mention it so it won't matter either way.
  • If you already did install FreeTDS via MacPorts, uninstall using: sudo port uninstall freetds +odbc and then sudo port uninstall unixODBC. Make sure you uninstall all instances of FreeTDS. If you have more than one, you'll get a notice when you run uninstall that you need to specify the version to uninstall.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download