Using PHP with Datadirect Connect ODBC Drivers - UNIX/Linux

Download the PDF

A common PHP configuration in UNIX/Linux environments uses PHP 5.1 running on Red Hat Linux Enterprise 4 with Apache 2.2. The following table lists sources for acquiring the necessary software:

PHP 5.1

Red Hat Enterprise 4

Apache 2.2

DataDirect Connect for ODBC

Install DataDirect Connect for ODBC

Install the DataDirect Connect for ODBC drivers. Fifteen-day evaluation copies are available at

Follow the instructions in the DataDirect Connect and Connect XE for ODBC User's Guide for setting environment variables and configuring a data source through the odbc.ini file.

Build PHP 5.1

Instructions for building PHP 5.1 as an Apache 2 shared module can be found at These instructions along with the following steps will guide you through the build process.

  1. Follow the instructions up to the statement: "Now, configure your PHP."

  2. Set the environment variable ODBC_HOME to point to your installation of the DataDirect Connect for ODBC drivers, for example:
    ODBC_HOME=/opt/DataDirect/ODBC; export ODBC_HOME
    ODBCINST=/opt/odbc32v52/odbcinst.ini;export ODBCINST
  3. In the $ODBC_HOME/include directory, create a file named odbc.h with the following contents:
    #include <sql.h>
    #include <sqlext.h>
    #include <odbcinst.h>
  4. Set the following environment variables to include DataDirect header (.h) files:
    CPPFLAGS="-I$ODBC_HOME/include"; export CPPFLAGS
  5. Set the following environment variables to link DataDirect libraries:
    CUSTOM_ODBC_LIBS="-L$ODBC_HOME/lib -lodbc -lodbcinst";
     export CUSTOM_ODBC_LIBS
  6. Add the following directive to the "configure your PHP" step found in the PHP installation instructions:
    ./configure --with-apxs2=/home/apache2/bin/apxs
    --prefix=/home/php5.1 --with-custom-odbc=$ODBC_HOME
    Replace /home/ with the appropriate directory for your setup.

  7. Continue with the PHP installation instructions for the make command until you reach the apachectl start command. Before starting Apache, add the following environment variables to the envvars file found in the bin directory of Apache. For example:
    An alternative is to specify the environment variables in each PHP script, such as:
    putenv("ODBCINST=/opt/DataDirect/odbc/odbcinst.ini ");
    //the rest of the connection code...
    Consult the Apache and PHP documentation for more information on setting environment variables.

  8. An optional step is to verify that the PHP module can load all of the dynamic modules it requires by running an ldd command against the file found in the modules directory of your Apache home directory. The output should include references to the,, and shared object files that are found in the $ODBC_HOME/lib directory.

  9. After starting your Apache server, you can verify your PHP installation by running a script with the phpinfo() function such as:
    <?php phpinfo(); ?>
  10. If ODBC support is included, the output of the phpinfo() function will include an ODBC section with the following settings:

    ODBC Support


    Active Persistent Links


    Active Links


    ODBC Library







    -L$ODBC_HOME/lib -lodbc –lodbcins

    Note: $ODBC_HOME will be replaced with the value you specified at build time.