Connecting to Microsoft SQL from PHP (GNU/Linux)      2003.07.18 @ 8:21:05 AM
This one is interesting. I have seen tons of guides on the web but none of them seem to work for me (I tried on RedHat 8 and RedHat 9 machines)
I have found some articles in PHP.NET and Linux Journal (using unixODBC), but the only way to get it to work right was by installing freetds as follows:

First, get the latest stable versions for freetds, apache and php (yes, you will have to recompile php, and apache if you have installed it from the RPMs):


Install FreeTDS:
cd freetds-0.61
./configure --enable-msdblib
make install

Install Apache:
tar -zxf httpd-2.0.47.tar.gz
cd httpd-2.0.47
./configure --enable-so
make install
cd ..

Install PHP:
tar -jxf php-4.3.2.tar.bz2
cd php-4.3.2
./configure --with-apxs2=/usr/local/apache2/bin/apxs
make install
cp php.ini-dist /usr/local/lib/php.ini

Make sure apache is properly configured to load PHP:
vi /usr/local/apache2/conf/httpd.conf

Make sure the following two lines exist
LoadModule php4_module modules/
AddType application/x-httpd-php .php

Presto!. Now start your apache with /usr/local/apache2/bin/apachectl start, and here is some php sample code:

# Replace your MS SQL Server IP address, username and password below
$link = mssql_connect("", "phptest", "phptest");
# A query string
$res1 = mssql_query("SELECT * from phptest", $link);
$rs = mssql_fetch_row($res1);
print "Here is your MS SQL data: $rs[0]";


All knowledge and software published in this website is released under the GNU General Public License (GPL)