PHP
Prev | Chapter 7. How to get what works with it working | Next

## PHP

There are three options for building PHP with support for FreeTDS corresponding to the three APIs that FreeTDS supports: `DB-Library`, `CT-Library`, and `ODBC`.

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

### `DB-Library`

PHP can be configured with `DB-Library` 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-Library` for “Sybase”

First build FreeTDS normally.

    	$ ./configure --prefix=/usr/local/freetds
    	$ make
    	$ sudo make install

Then build PHP with support for “Sybase”

    	$ cd php
    	$ ./configure --with-sybase=/usr/local/freetds
    	$ make
    	$ sudo make install

And that's it!

### `CT-Library`

Option 2 is to use the `CT-Library` 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-Library` in with `DB-Library`, above. Then configure PHP with `CT-Library`.

    	$ 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
    	$ sudo 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 Preparing ODBC. Then build PHP with support for ODBC.

    	$ cd php
    	$ ./configure --with-iodbc=/usr/local
    	$ make
    	$ sudo make install

Now everything should run. There is a sample PHP script in the FreeTDS samples directory called `odbctest.php`.

Prev | Up | Next
Perl | Home | Python