I'm doing wrong.
I'm trying to connect to a remote AS400 database using odbc & php.
Here's my environment:
Server: RedHat ES 2.1
IBM HTTP Server (was pre-built by IBM):
Server version: IBM_HTTP_Server/2.0.47.1 Apache/2.0.47
Server built: May 20 2004 16:46:47
Build level: WWWIHS2047/web_IHS0420.04
Server's Module Magic Number: 20020903:4
Architecture: 32-bit
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/worker"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D HTTPD_ROOT="/opt/IBMIHS"
-D SUEXEC_BIN="/opt/IBMIHS/bin/suexec"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
PHP 4.3.10, configured with:
../configure --prefix=/usr/local/php --with-apxs2=/opt/IBMIHS/bin/apxs
--with-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config
--with-libxml-dir=/usr/lib --with-ibm-db2=/opt/IBM/db2/V8.1
--with-unixODBC=/usr/local
unixODBC v2.2.11 compiled w/ defaults per the INSTALL file
IBM iSeriesODBC v5.1.0-0.16 installed by RPM
My odbc.ini & odbcinst.ini are both in /usr/local/etc
From the command line on the server, I can query the AS400 via unixODBC (where foo = dsn):
#isql -v foo
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
From my php script, I get:
Warning: odbc_connect(): SQL error: [IBM][CLI Driver] SQL1013N The
database alias name or database name "foo" could not be found.
SQLSTATE=42705 , SQL state 08001 in SQLConnect in
/opt/IBMIHS/htdocs/en_US/test.php on line 7
Cannot connect to the database.
So obviously PHP isn't finding the datasource. Why? What do I need to
do to configure PHP to use the DSNs in odbc.ini?
Just for giggles, I've added
ODBCINI=/usr/local/etc/odbc.ini
export ODBCINI
to /opt/IBMIHS/bin/envvars thinking that would let apache pick up the
odbc.ini... doesn't make a difference.
For what it's worth, here's my PHP code:
<?
$username = "user";
$password = "pass";
$host = "foo";
$connect = odbc_connect("$host", "$username", "$password") or
die("Cannot connect to
the database.<br>" . mysql_error()); ;
$query = "SELECT * FROM QLIB.FOO";
$result = odbc_exec($connect, $query);
while(odbc_fetch_row($result)){
$LEMP = odbc_result($result, 2);
print("<b>NAME:</b>$LEMP<br><b>ADDRESS:</b>foo<br><br>\n");
}
odbc_close($connect);
?>
Same code works fine on a Windows box w/ apache & php with a windows
DNS...
I've read the unixODBC docs, the IBM docs, the php docs... can't figure
out what I'm missing..
Help?
Thanks,
Kelly