PHPBuilder - Microsoft SQL Server from PHP on Linux Page 2

RSS Twitter

Microsoft SQL Server from PHP on Linux - Page 2

by: Alberto Dainotti
September 19, 2000

Sybase Client Library

Now, forget about the outdated libraries or the ones linked in php faq, unless you still have a libc5 system. (If you have a libc5 system you can download the libraries at
The client library is distributed with Sybase Adaptive Server Enterprise, which can be downloaded for free from Currently, Sybase Adaptive Server Enterprise for Linux version 11.9.2 is offered as a free release for development; support can be purchased separately. Download at least the file named sybase-common-11.9.2-1.i386.rpm, which contains the only files you need to compile php. It is just 5 Mb of download.
Next, unpack the files. I will assume the installation directory is /opt/sybase. Go to the php source directory and do a ./configure adding "--with-sybase-ct=/opt/sybase" to the usual configure options.
After having compiled and installed php, you need to add the location of the libraries to your library path. You can copy the shared libraries to /usr/local/lib; add the path to /etc/; or simplyadd the line below to apachectl:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/sybase/lib
The next thing you need to do is to declare the environment variable SYBASE to point to the sybase installation directory. If Sybase Open Client Library is loaded without this variable correctly set, it segfaults (apache segfaults) !! So you can add to apachectl:
export SYBASE=/opt/sybase
Now you must edit the "interfaces" file, which must be located in the installation dir. The interfaces file contains information about remote servers. A typical configuration to access a Windows machine with MS SQL installed with ip and listening on port 1433 connected to the local lan (eth0) is this:
	query tcp eth0 1433
	master tcp eth0 1433
The name "relaxsql" is the hostname which will be used by php functions to establish a connection to MS SQL on that machine. Be sure to set the correct permissions to the sybase installation directory and to this file; apache must have read access to this file.
Here is a sample php code to test everything. It connects as user "utente" with password "parola" and makes two queries to the default database for that user, as defined in MS SQL Server.


mssql_connect('relaxsql' 'utente' 'parola' );
echo (
"ConnectID: $numero<br>\n");

$result=mssql_query('select * from tavoladiprova',$numero );
while (
$row=mssql_fetch_array($result)) {
    echo (
"$counter c1: $c1 c2: $c2<br>\n");

$result=mssql_query('INSERT into tavoladiprova values('kooooo','ooooook')',$numero);


The default TDS protocol version used by sybase client library is TDS 5.0. In order to convince php to use TDS4.2 I've made a quick and dirty patch to the php code. This patch is against php-4.0.1pl2; you can use it if you want TDS 4.2.

« Previous Page
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Alberto Dainotti



(Maximum characters: 1200). You have characters left.