The simple steps:
- if you do not have them, download ODBC drivers from http://www.openlinksw.com
The do the following. I use this in my linux system but try to edit it for windows. If you can't mail me and i will edit it and mail it to you.
Compiling PHP with linked iODBC Driver Manager as an Apache shared module.
The process is fairly straightforward. You will need to be a user who has sufficient privileges to perform all of these steps as well. Root privileges can be gotten by “su – root” and entering your root password, but be forewarned that you can easily destroy your system as root. If you use root privileges please do so on a test machine.
1.Setup a build location, and get the latest builds of iODBC, Apache, and PHP:
Open a terminal window
cd /usr/local/src
An iODBC .taz archive for your platform may be downloaded from http://www.iodbc.org/opliodbc.htm. As of this writing the latest version is 3.0.4
Copy that to your /usr/local/src and: tar xzf <archive_name>.taz
Apache may be downloaded here:
http://httpd.apache.org/dist/httpd/apache_1.3.19.tar.gz
Copy that to your /usr/local/src and: tar xzf apache_1.3.19.tar.gz
PHP source is available here: http://www.php.net/distributions/php-4.0.4pl1.tar.gz
Copy that to your /usr/local/src and: tar xzf php-4.0.4pl1.tar.gz
- Set some environment variables:
export LD_LIBRARY_PATH=/usr/local/src/odbcsdk/lib - this tells the compiler where to find the driver manager.
If you prefer to statically link iODBC then remove or rename libiodbc.so from the above path and libiodbc.a will be statically linked instead.
- Apache: configure
a. cd apache_1.3.x
b. ./configure --prefix=/www
- PHP: configure, make, make install
a. cd ../php-4.x.x
b. ./configure –with-iodbc=/usr/local/src/odbcsdk --with-apache=../apache_1.3.x --enable-track-vars
c. make
d. make install
This will add a directory to your Apache source directory under src/modules/php4.
- Apache: reconfigure, make, make install.
a. cd ../apache_1.3.x
b. ./configure –prefix=/www --activate-module=src/modules/php4/libphp4.a
c. make
d. make install
- PHP: copy your php.ini over:
a. cd ../php-4.x.x
b. cp php.ini-dist /usr/local/lib/php.ini
- Apache: configure and start:
a. edit your httpd.conf and uncomment (remove the "#") from these lines:
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps
b. /www/bin/apachetl start (or restart)
- PHP: check your installation
a. create a text file called php.info with the following in it: <?php phpinfo(); ?>
b. put it in your /www/htdocs/ directory
c. point your browser to http://localhost/info.php to see your configuration setup.
- Notes: when starting apache in the future, you will need to have LD_LIBRARY_PATH set.
e.g. export LD_LIBRARY_PATH =/usr/local/src/odbcsdk/lib
The path in this statement indicates where you have stashed libiodbc.so
An easy way to do this automatically is to place a setenv to it in your .login or .profile, etc.
The location of your shared iODBC support is set by this environment variable.
If it's not set, apache will give an error when starting as it cannot find libiodbc.so.
Also, you can upgrade your iODBC version simply by updating to a newer file (overwriting),
To test a new libiodbc.so before overwriting the old you, you can temporarily set LD_LIBRARY_PATH to point to an new libiobc.so.
- Sample Connection:
Notice the putenv’s. These variables include ones necessary for an Openlink driver connection. Third-party drivers used with iODBC may require different environment variables. I usually put all the necessary variables in an putenv.inc.php file, and ‘require_once()’ it at the beginning of each script that wants ODBC connectivity. Not a huge deal for a small site with 3 putenv’s on each page, but in practice you could have many pages with many environment variables on each one. It’s cleaner to only be able to make mistakes in one place. This also allows you to apply different sets of env’s to different scripts, interchanging values with great flexibility.
<?php
putenv("LD_LIBRARY_PATH=/usr/local/src/odbcsdk/lib");
putenv("ODBCINSTINI=/path/to/odbcinst.ini"); //this location will be determined by your driver install.
putenv("ODBCINI=/path/to/odbc.ini"); //odbc.ini contains your DSNs, location determined by your driver install.
$dsn="DSN=DSN_NAME"; // this is a valid DSN‚ can be tested in odbctest
$user="username";
$password="password";
$sql="SELECT * FROM table"; //replace “table” with a table name
if ($conn_id=odbc_connect("$dsn","","")){
echo "connected to DSN: $dsn";
if($result=odbc_do($conn_id, $sql)) {
echo "executing '$sql'";
echo "Results: ";
odbc_result_all($result);
echo "freeing result";
odbc_free_result($result);
}else{
echo "can not execute '$sql' ";
}
echo "closing connection $conn_id";
odbc_close($conn_id);
}else{
echo "can not connect to DSN: $dsn ";
}
?>
- Additional Sources of Info
The PHP manual, install instructions: http://www.php.net/manual/en/install.macosx.php
The iODBC forum: www.iodbc.org
The PHP mailing lists: http://www.php.net/support.php
Openlink Software Online Support, at http://www.openlinksw.com/support/suppindx.htm
Openlink Software Discussion Forums, at http://www.openlinksw.com/support/teclinks.htm
Openlinkís ODBC Whitepapers, at http://www.openlinksw.com/info/docs/odbcwhp/tableof.htm