Actual Technologies
Deutsch Español English
 

Setting up PHP to use the ODBC Driver

Introduction

The Actual Technologies OBDC drivers can be used by PHP 4.3 and later. In order to use an ODBC driver with PHP, PHP must be built with the iODBC libraries. There are two different forms of the libraries available: the static libraries provided by Apple as part of the Xcode development tools, and the iODBC framework that is installed with the Actual ODBC Driver.

The default Actual ODBC license allows up to 5 concurrent open connections. Depending on the application and how connections are allocated (and deallocated) on the PHP page, 5 connections can support many more than 5 concurrent visitors to your site. We recommend that within a PHP page that you allocate the connection when you are ready to perform the query, execute the query, and then immediately close the connection.

Licenses that allow additional concurrent connections are available for $30 per block of 5 concurrent connections. Contact us at orders@actualtech.com to place an order.

Download and Build PHP 4.3 or Later

Follow the instructions for downloading, configuring, building and installing PHP provided by Apple

You will need to choose whether to build PHP with the Apple ODBC library or the iODBC framework. Which one you choose is a matter of personal preference. The Apple library is based on the iODBC version 3.06 code base, while the iODBC framework is based on the iODBC version 3.51 code base. For PHP purposes, there is not much of a functional difference between the two.

Building PHP with the Apple ODBC Library

First, use the Mac OS Terminal application in the /Applications/Utilities directory to verify that the following files exists: /usr/lib/iodbc.a

Next, change to your PHP build directory and configure PHP with the "configure" command and "--with-iodbc=/usr" as an argument. The exact form of the command will vary depending on your needs. Here is an example using the minimum number of parameters:

./configure --with-iodbc=/usr

A more useful configuration would be to simply add --with-iodbc=/usr to Apple's example. Build and install PHP and configure Apache according to Apple's instructions.

Building PHP with the iODBC Framework

The iODBC framework is included in the Actual ODBC Driver installation. PHP does not have native support for frameworks, so you will have to make some minor changes to the PHP Makefile after running "configure" but before running "make". Here's what you have to do:

  • Install the Actual ODBC Driver using the installer
  • Configure PHP with the "configure" command and your arguments, but do not include "--with-iodbc"
  • Using a text editor, edit the Makefile in the PHP build directory. Change the following lines:
Existing Change To
ODBC_INCLUDE = ODBC_INCLUDE = -framework iODBC
ODBC_LIBS = ODBC_LIBS = -framework iODBC
ODBC_LFLAGS = ODBC_LFLAGS = -framework iODBC
EXTRA_LIBS = list of libraries append -framework iODBC

Once you have saved your changes to the Makefile, continue following Apple's instructions starting with the "make" command.

Invoking ODBC Functions from PHP

Once you have verified that PHP is installed correctly and Apache is configured correctly, you can begin writing your PHP page. The complete list of functions is available at the PHP website.

The biggest challenge with getting PHP to work with an ODBC driver will be issues related to the user account that PHP is running under having sufficient privileges to access the files on the file system needed by the iODBC driver manager and the ODBC driver. For example, when OS X boots up, PHP is typically running as root. If you then stop and restart "Personal Web Sharing" with System Preferences, PHP will be running with your user account.

To avoid problems associated with the driver looking for configuration files in different locations based on the user PHP is running under, we recommend that you set environment variables in your PHP page to tell the iODBC driver manager and the Actual ODBC Driver where to look for the files, and put the files (or links to the files) in a shared location where they can be read regardless of the user context.

Since the configuration file for System data sources (odbc.ini) is already in a folder that is accessible by all users (/Library/ODBC), you can set the path to that file using the following statements at the top of your PHP page:

putenv("ODBCINSTINI=/Library/ODBC/odbcinst.ini");
putenv("ODBCINI=/Library/ODBC/odbc.ini");

A very simple example PHP page is available. It shows how to set the environment variables and call simple ODBC commands.


 
(c) 2024 Actual Technologies, LLC Politique de confidentialité