Wednesday, August 26, 2009

Linux, PHP, and MSSQL Server

I don't know if this will work for everyone, but it took me 2 days to figure this out so maybe it will help you.

I wanted to connect to an external SQL Server 2000 database from a hosted Linux database. From the Linux box I was able to ping, telnet, and tsql the database server, but PHP would always throw a "unable to connect to database error".

PHP, in my case, uses FreeTDS to interface with MSSQL. My hosting provider has the default version of FreeTDS set to 5.0. After many hours of research I figured out that I needed to use version 7.0. So to get it to work I just set the version to 7.0 in my PHP script with the following line of code:


And that was all folks. (Remember that when you use mssql_connect with Linux that you want to probably add the port number to the host. e.g. mssql_connect(, $user, $pwd ) ).

No comments: