#native_company# #native_desc#
#native_cta#

Microsoft SQL Server from PHP on Linux Page 3

By Alberto Dainotti
on September 19, 2000

FREETDS

FreeTDS can be downloaded from www.freetds.org. I suggest downloading the latest snapshot,
which gave me better results and seems to have less bugs. (At the time of this article, the latest
snapshot is dated Jul 6 2000). The direct link is:
ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/current/freetds-current.tgz.
Alternatively, you can download the latest CVS. The information needed to download is in the FAQ on the main site.
As previously stated, freeTDS supports TDS 7.0 and will let you take advantage of its features.
Therefore, it could be a better choice if you need to connect to MS SQL Server 7.
Also, freetds is an open source project under constant development, with all the advantages
this implies. Personally, it is the solution I prefer among all.
Unpack the files and do a configure:
./configure –with-tdsver=4.2 –enable-msdblib –enable-dbmfix –with-gnu-ld –enable-shared –enable-static
(The tdsver options simply sets the default protocol, this can be changed anytime at runtime)
The default installation directory is /usr/local/freetds.
After you have patched a clean php-4.0.1pl2 package (“patch -p0 < patch.freetds” from the
parent dir of the source package), you can build php with the configure option
"--with-sybase-ct=/usr/local/freetds"
As for the sybase library, the environment variable SYBASE pointing to the freetds installation
directory needs to be declared. If the variable isn’t declared, apache starts correctly and only the php sybase/mssql functions
won’t work. You can do this in apachectl or directly in your php code. It is also possible to set the tds protocol version from an environment variable
and to set a debug logfile (warning: it grows rapidly):

<?php

//putenv('TDSDUMP=/tmp/tds.log');

putenv('SYBASE=/usr/local/freetds');

putenv('TDSVER=70');

?>



Finally, you must correctly edit the file /usr/local/freetds/interfaces, as explained in
the previous section regarding sybase libraries. One interesting difference is that the
third field of a configuration row can be used to specify a default protocol for that
specific host:
	myserver
	query tcp tds4.2 127.0.0.1 1433
	master tcp tds4.2 127.0.0.1 1433
You can test your installation/configuration with the simple php code reported above.