PHPBuilder - Microsoft SQL Server from PHP on Linux Page 4

RSS Twitter

Microsoft SQL Server from PHP on Linux - Page 4

by: Alberto Dainotti
September 19, 2000


ODBC introduces an overhead to connection time because the layers of communication are more. The client machine needs to have an ODBC driver manager which is directly interrogated by the application. The driver manager establishes a connection with a remote ODBC server by using a specific ODBC driver resident on the client machine; the ODBC server on the server machine translates ODBC calls and speaks to the database. The driver manager and the driver itself are independent. Therefore, it is to the driver manager that we must link php if we want odbc connectivity.
ODBC has the advantage of allowing applications to be written which theoretically are independent from the dbms. If you need to change the dbms, you just have to change the driver, not the code.
ODBC is a programming API and doesn't cover a client/server protocol. Therefore, if you want to communicate from a client machine (unix) to a remote machine (windows) using odbc you need a driver which handles the client/server connection. In other words, a bridged driver which resides both on the client machine and on the server machine. The client side of the driver will keep the requests from the local odbc driver manager, and will handle the connection to the server side driver. Depending on its implementation, the server side driver could speak directly to the database or use a local odbc driver.
An alternative implementation to establish a client/server connection is that the local ODBC driver will translate ODBC calls in to the language of the destination database. This will connect to the dbms directly. (This is the case of Inline's driver which you will read about later).
Here are listed the packages that allow an odbc solution. It is strange that php FAQ report only the openlink's driver..
ODBC driver managers for linux:
- iODBC ( is an opensource odbc driver manager and SDK mantained by Openlink Software ( which also has a similar odbc driver manager distributed only in binary form.
- unixODBC ( The unixODBC Project goals are to develop and promote unixODBC to be the definitive standard for ODBC on the Linux platform. It is an opensource project. This project is supported by Easysoft (

Each of these driver managers are supported under php. You must choose one odbc driver manager and build php linking against its libraries:

To link against iodbc:--with-iodbc=
Warning: I had a problem building php as a Dynamic Shared Object for apache (--with-apxs option) and linking it to a driver manager. This occurs if you build apache with DSO option. Apache doesn't build with libpthreads, while driver managers do this by default. This conflict leads to a segmentation fault when apache starts. The solution is to rebuild apache with libpthreads (rm config.cache and do "LDFLAGS=lpthreads ./configure --prefix=/www --with-apxs etc..") or build the driver manager without libpthreads ("./configure --enable-threads=no etc.."). Thanks to Nick Gorham of Easysoft for the help.
The driver manager reads a configuration file called DSN (usually /usr/local/etc/odbc.ini) which lists Data Sources. This is a combination of several options as ipaddress, tcp port, default db, user pass, but the most important is the path to the specific odbc driver which the connection relies upon.

« 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.