Introduction
The Actual Technologies ODBC drivers can be used with PHP if the PHP module is configured to include ODBC support. Mac OS X 10.5 "Leopard" includes PHP configured for ODBC - you only need to follow a few steps to enable it. Earlier versions of Mac OS will require you to install the PHP module separately. See the instructions below for details.
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.
We also have a "Professional Edition" license that allows up to 10 connections and a "Server Edition" that allows up to 250 concurrent connections. Please visit our on-line store for pricing information.
Mac OS X 10.5 "Leopard"
In order to use the built-in PHP module with Mac OS X 10.5, you will need to edit a configuration file. First, use the System Preferences to disable "Web Sharing" in the Sharing panel. Then use the Terminal application in /Applications/Utilities to edit the file:
sudo pico /etc/apache2/httpd.conf
Locate the following line within the file, and remove the "#" at the beginning of the line:
LoadModule php5_module libexec/apache2/libphp5.so
Locate the section containing lines starting with "AddType", and insert the following lines:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Since Apache is a 64-bit process, you will need to use Version 3 of the Actual ODBC drivers. Version 3 drivers are compatible with 64-bit applications such as Apache. The latest drivers can be downloaded here. You can upgrade your Version 2 license key here.
Now restart Web Sharing in the System Preferences, and continue with the instructions for "Invoking ODBC Functions from ODBC" below.
Mac OS X 10.4 "Tiger" or earlier
In order to use an ODBC driver with PHP on Mac OS X 10.4 or earlier, PHP must be built with the iODBC libraries. Follow the instructions for downloading, configuring, building and installing PHP provided by Apple
.Now use the Mac OS X 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.
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.