473,654 Members | 3,184 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_SENDFIL E
-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_U NSERIALIZED_ACC EPT
-D APR_HAS_OTHER_C HILD
-D AP_HAVE_RELIABL E_PIPED_LOGS
-D HTTPD_ROOT="/opt/IBMIHS"
-D SUEXEC_BIN="/opt/IBMIHS/bin/suexec"
-D DEFAULT_SCOREBO ARD="logs/apache_runtime_ status"
-D DEFAULT_ERRORLO G="logs/error_log"
-D AP_TYPES_CONFIG _FILE="conf/mime.types"
-D SERVER_CONFIG_F ILE="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($conn ect, $query);

while(odbc_fetc h_row($result)) {
$LEMP = odbc_result($re sult, 2);
print("<b>NAME: </b>$LEMP<br><b>A DDRESS:</b>foo<br><br>\n ");
}

odbc_close($con nect);
?>

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 3497
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_SENDFIL E
-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_U NSERIALIZED_ACC EPT
-D APR_HAS_OTHER_C HILD
-D AP_HAVE_RELIABL E_PIPED_LOGS
-D HTTPD_ROOT="/opt/IBMIHS"
-D SUEXEC_BIN="/opt/IBMIHS/bin/suexec"
-D DEFAULT_SCOREBO ARD="logs/apache_runtime_ status"
-D DEFAULT_ERRORLO G="logs/error_log"
-D AP_TYPES_CONFIG _FILE="conf/mime.types"
-D SERVER_CONFIG_F ILE="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($conn ect, $query);

while(odbc_fetc h_row($result)) {
$LEMP = odbc_result($re sult, 2);
print("<b>NAME: </b>$LEMP<br><b>A DDRESS:</b>foo<br><br>\n ");
}

odbc_close($con nect);
?>

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
1881
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 am basicly using a dictionary to update a access database using an odbc connector. I am able to connect and it seems that I am able to loop through the code to update all the rows I need to. The one weird bug I seem to get is what ever is the...
5
102527
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! - DataDirect 5.0 Oracle Wire protocol (3rd party ODBC driver): connection works when I hit the driver's "test connection"
4
7228
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 to make ODBC calls to the db. The particular system I'm working with, will not work with an Oracle stored procedure I'm told. However, it
4
5644
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
6178
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 the Administrative Tools>Data SOurces (ODBC) menu? IS there a way to do this with VBA code from my installer disk, or by simply copying a file onto the user's PC? Any help is appreciated. LQ
1
5520
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 table of the MS-SQL Database, "TestODBC". I wanted to use StoredProcedure1 as the bound recordsource for a new form Form1. But I
4
335
by: Scott | last post by:
Is there a way to simulate an ODBC connection on my desktop? Using WindowsXP. Thanks! Scott
8
9628
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 work from
16
9177
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
1359
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: ---------------------------------- import sys, os # find odbc module in Python distribution tree:
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8708
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.