PHP – Connecting to MS SQL

How to connect PHP to a MS SQL server from a Linux server


Install PHP and FreeTDS etc..

get php up and running with apache – then

# apt-get install php5-sybase php-pear php5-dev

Download FreeTDS from

# tar zxvf freetds-stable.tgz
# cd freetds-0.6.4/
# ./configure --prefix=/usr/local/freetds
# make
$ make install


Create the /usr/local/freetds/freetds.conf file

put this in the file:

# A typical Microsoft SQL Server 2000 configuration
host =
port = 1433
tds version = 8.0

And here is the PHP code:

$db_conn = mssql_connect("MyMSSQLDB","sa","<password>") 
or die( "<strong>ERROR: DB Connection failed</strong>" );

Leave a Reply

Your email address will not be published.