473,326 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Can't get ODBC to work with PHP

Hi, I've worked on this for a couple of days & can't figure out what
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

Jul 17 '05 #1
1 3471
we*******@gmail.com wrote:
Hi, I've worked on this for a couple of days & can't figure out what
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

I think the quotes around the user/pass/db fields are a bit of overkill,
and using odbc_error instead of mysql_error may shed a bit more light on
the problem???

Steve
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Chris | last post by:
Hello, I posted a while back about a newbie database question and got a lot of great help here. My script that I am creating has come a long way (For me!) and almost does what I need it too. I...
5
by: SerGioGio | last post by:
Hello, I am going nuts. I am trying to connect to my local ORACLE instance using ODBC. It used to work few weeks ago, but it fails now. Connection with: - SQL*plus: connection works! -...
4
by: Roger Redford | last post by:
Dear Experts, I'm attempting to marry a system to an Oracle 817 datbase. Oracle is my specialty, the back end mainly, so I don't know much about java or javascript. The system uses javascript...
4
by: Andreas Lauffer | last post by:
Can anyone tell me advantages / disadvantages of DataDirect Server Wire ODBC-driver? Any experiences? What about redistribution? Andreas Lauffer, easySoft. GmbH, Germany
3
by: Lauren Quantrell | last post by:
Maybe a dumb question - I'm new to ODBC. How do I install an Access ..mde file on a user's workstation and create the ODBC connection to the backend SQL Server database without having to go through...
1
by: Lyle Fairfield | last post by:
I created a new MS-SQL Database, "TestODBC". I made Table1 and StoredProcedure1. I made an ODBC DSN for that MS-SQL Database. I created a new AccessXP mdb, "TestODBC". I linked to the...
4
by: Scott | last post by:
Is there a way to simulate an ODBC connection on my desktop? Using WindowsXP. Thanks! Scott
8
by: Greg Strong | last post by:
Hello All, The short questions are 1 Do you know how to make DSN connection close in Access to Oracle 10g Express Edition? &/or 2 Do you know how to make a DSN-less pass-through query...
16
by: network-admin | last post by:
We have Problems with Access query on Oracle 10g Database with ODBC Connection. The Query_1 is such as select * from xtable where ycolumn <"S" Result = ODBC Faild...
5
by: boblatest | last post by:
Hello, it's still me, being unable to load certain modules (for instance, odbc) in scripts that run though IDLE. I've now written a self- containing script that illustrates the whole problem: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.