472,811 Members | 1,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 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 3430
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: ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.