PHP

There are three options for building PHP with support for FreeTDS corresponding to the three APIs that FreeTDS supports: db-lib, ct-lib, and ODBC.

Note

All these examples build the CGI version. Consult PHP's documentation for building the Apache module and including other extensions.

db-lib

PHP can be configured with db-lib access for a "Sybase" server (which also works with Microsoft servers), or with the mssql extension, intended exclusively for Microsoft servers.

Example 7-6. PHP and db-lib for "Sybase"

First build FreeTDS normally.

$ ./configure --prefix=/usr/local/freetds
$ make
$ su root
Password: 
$ make install

Then build PHP with support for "Sybase"

$ cd php
$ ./configure --with-sybase=/usr/local/freetds
$ make
$ su root
Password: 
$ make install

And that's it!

ct-lib

Option 2 is to use the ct-lib API. Again here, we run into minor difficulties at build time. Applications linking with Sybase's OpenClient have to link in a handful of libraries and these libraries vary slightly from platform to platform. When creating FreeTDS it was decided that there would be only one library: libct. This saves a great deal of library naming conflicts that Sybase ran into (e.g. libtcl is used both by Sybase and the language TCL), however some applications like PHP assume that all the Sybase libraries will be present. So, some hand editing of the Makefile is necessary to remove these extra libs. Build FreeTDS just as you would for db-lib in with db-lib, above. Then configure PHP with ct-lib.

$ cd php
$ ./configure --with-sybase-ct=/usr/local/freetds
Now edit the Zend/Makefile looking for the libZend_la_LDFLAGS line and remove -lsybtcl -lintl -lcomn and -lcs, leaving the -lct. Then proceed to make and install PHP.
$ make
$ su root
Password: 
$ make install
We hope an upcoming version of PHP will automatically detect the presence of FreeTDS and include only the -lct library.

ODBC

The third and newest option is to use the FreeTDS ODBC driver with PHP. First build the iODBC or unixODBC driver manager and FreeTDS as detailed in this guide. Then build PHP with support for ODBC.

$ cd php
$ ./configure --with-iodbc=/usr/local
$ make
$ su root
Password: 
$ make install
Now everything should run. There is a sample PHP script in the FreeTDS samples directory called odbctest.php.