Installing MSSQL Module for PHP on Mac OS X

For two days I try to connect my php script on MacOSX to Microsoft SQL Server 2000. All my attempts failed until I use dtruss. Finally I can connect to MSSQL from MacOSX with FreeTDS.

At first i want to say Thank you Xavier Perseguers for his article MSSQL Support for PHP.
Below I quote part of his article with my edits and comments.
On Mac OS X, you would use MacPorts and package php5-odbc and freetds:

Then edit/create file /opt/local/etc/freetds/tds.driver.template:

Then prepare your DSN into /opt/local/etc/freetds/tds.dsn.template:

Edit file /opt/local/etc/freetds/freetds.conf:

Register the driver and your DSN:

Those commands are the official way of modifying files /opt/local/etc/odbcinst.ini and /opt/local/etc/odbc.ini but you may of course modify them manually.
Testing the System
It is possible to test the connection with isql:

But it never worked for me until I found the underlying cause (Google was of no help although many users had this problem). I always got following error:
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[ISQL]ERROR: Could not SQLConnect
The trick is to export variable ODBCINI:

Another test you may perform before going on configuring your TYPO3 website is with a simple PHP script:

If you had to export the ODBCINI variable, you likely will have to do it too for Apache2, otherwise TYPO3 will fail to connect to your MSSQL database with the same error message.
Edit file /opt/local/apache2/bin/envvars and add this to the end:
Or /Applications/MAMP/Library/bin/envvars if you use MAMP

Then restart Apache.
PHP Configuration
Last but not least, edit your php.ini file:

and this in the MSSQL section:

Join the Conversation


  1. Спасибо, только подскажите, на какой (или каких) версии PHP вы это реализовывали?
    Очень буду благодарен за оперативный ответ.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.