Last updated on: Sunday, July 06, 2008
Software
Information
Community
News
Fun
Credits
|
unixODBC/PHP/Linux on S390/and PostgreSQL
This information was originally posted to the
Linux-390 mailing list on February 9, 2001, by James Rivard.
Thanks to help from the list, especially Bernhard Kaindl, I now am able to
use PHP with ODBC and the unixODBC driver manager to connect to a
PostgreSQL database. My goal, once we get the correct version of
DB2/Connect in house, is to use PHP/ODBC to connect to a remote DB2 database
on OS/390.
Here are some notes to hopefully make life easier for someone else in the
future:
- Install the RPM for Postgres if you want to use postgres. The binary RPM
is fine. The build for unixODBC needs the postgres libraries in order to
build the postgres odbc driver. The odbc driver included with the pg_odbc
RPM will NOT work with PHP/unixODBC. (I tried. If you try to use it you get
an error on the odbc_connect() about missing server name, port, etc... no
matter what you put in odbc.ini.) If you are not using postgres, the
unixodbc web site has information on other drivers. There is a section in
the doc area for DB2.
- You do not have to touch Apache. unixODBC will be installed as a DSO
module.
- Download the source for unixODBC from
http://www.unixodbc.org. Build with the following commands, or whatever
suits your needs. Note that the SuSE RPMs put some packages in libraries
that are not included by the compiler by default so you need CFLAGS specified.
cd ./unixODBC.x.x.x
libtoolize --copy --force (this will make the configure script recognize
s390 as a host - thanks to Bernhard for this one)
CFLAGS="-I/usr/local/include -I/usr/include/mcal -I/usr/include \
-I/usr/include/pgsql -I/usr/include/mysql"
export CFLAGS
./configure
make
make install
Note: I did not install Qt so the command line interface (odbcinst) was used
to add drivers and DSNs (see http://www.unixodbc.org).
The version of unixODBC I downloaded required Qt 2.2 or higher, which is later than what SuSE 7
shipped with. I downloaded the SRPM for such a version but the RPM on my
SuSE system won't install it (major version <=3 error). From what I can
gather I need a newer version of RPM or a patch. It wasn't worth the hassle
to me just to get a GUI interface which I probably will seldom use anyways.
- Update odbcinst.ini and odbc.ini as indicated by
the documentation. odbcinst.ini has information on the drivers you
want to use and odbc.ini is where the DSNs are stored. These can
be updated on "the fly" without taking down any services. I used the odbcinst
command to make updates.
- PHP4 was used - since the default RPM install from the CDs does not
include ODBC driver manager support, at least on SuSE, I needed to install
the source RPM for PHP4. There is one on the SuSE CD2 or CD3, or you can
download the latest from http://www.php.net/ or
http://rpmfind.net/.
- If you get a file called number4.tar.gz copy it to php-4.x.x.x and
untar it. It will update ./php-4.x.x.x/ext/bcmath and allow the bcmath
functions to compile.
- Configure with the following (I ran "<?phpinfo()?>" from a PHP web page
after the original PHP4 binaries were installed to get most of this info).
The result will be the same as the binary install plus the unixODBC driver
manager.
CFLAGS="-I/usr/local/include -I/usr/include/mcal -I/usr/include \
-I/usr/include/pgsql -I/usr/include/mysql"
LDFLAGS=
CUSTOM_ODBC_LIBS="-L/usr/local/lib -lodbc"
export CFLAGS LDFLAGS CUSTOM_ODBC_LIBS
./configure --with-pgsql=/usr \
--with-mysql=/usr \
--with-gd=shared \
--with-tiff-dir=/usr \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-ldap=yes \
--with-imap=yes \
--with-zlib=yes \
--with-xml \
--with-ttf \
--with-mcal=/usr \
--with-ftp \
--with-ndbm \
--with-gdbm \
--with-snmp \
--with-mm \
--with-config-file-path=/etc/httpd \
--with-apxs=/usr/sbin/apxs \
--with-exec-dir=/usr/lib/apache/bin \
--enable-versioning \
--enable-yp \
--enable-trans-sid \
--enable-inline-optimization \
--enable-track-vars \
--enable-magic-quotes \
--enable-safe-mode \
--enable-sysvsem \
--enable-sysvshm \
--enable-bcmath \
--enable-calendar \
--enable-ftp \
--enable-memory-limit \
--enable-wddx \
--with-readline
--with-unixODBC=/usr/local
- Update php.ini (normally in /etc/httpd) to include:
extension_dir = /usr/local/lib/php/extensions/no-debug-non-zts-20001214
extension = odbc.so
---thanks again to Bernhard for this one.
- You may need to update /etc/ld.so.conf and then run ldconfig so that some
of the modules are found. Some libraries to add might include:
/usr/local/lib/php
/usr/lib/pgsql
/usr/lib/mysql
- Update /etc/httpd/httpd.conf to include information on loading PHP4
modules. If you already installed the PHP4 binaries before compiling the
source code, you won't have to do this. See the PHP INSTALL file for the
statements (LoadModule, AddModule, AddType).
- Restart Apache.
- Configure the database and database security as needed and try running
"odbc_connect()" from a .php web page.
Misc Notes:
|