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

http://www.php.net/downloads.php

Red Hat Enterprise 4

http://www.redhat.com

Apache 2.2

http://httpd.apache.org/download.cgi

DataDirect Connect for ODBC

http://forms.progress.com/forms/driverdownload

Install DataDirect Connect for ODBC

Install the DataDirect Connect for ODBC drivers. Fifteen-day evaluation copies are available at http://web.datadirect.com/techres/odbc.htmhttp://www.progress.com/products/datadirect-connect/odbc-drivers/odbc-developer-center/odbc-product-documentation.

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 http://www.php.net/manual/en/install.unix.apache2.php. 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:
    ODBCINI="$ODBC_HOME/odbc.ini"
    ODBCINST="$ODBCINST"
    
    An alternative is to specify the environment variables in each PHP script, such as:
    <?php
    putenv("ODBCINI=/opt/DataDirect/odbc/odbc.ini");
    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 libphp5.so file found in the modules directory of your Apache home directory. The output should include references to the libodbc.so, libivicuxx.so, and libodbcinst.so 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

    Enabled

    Active Persistent Links

    0

    Active Links

    0

    ODBC Library

    custom

    ODBC_INCLUDE

    -$ODBC_HOME/include

    ODBC_LFLAGS

    -$ODBC_HOME/lib

    ODBC_LIBS

    -L$ODBC_HOME/lib -lodbc –lodbcins


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