I think I will die! Does anyone know how to get data from a table on AS400 displayed with PHP through ODBC? I'm starting to go mad. I tried ODBC drivers (iSeries Access client, Client Access). Nothing helps.
I have Apache server as localhost on my machine and php installed and that works fine.
The same DSN connection I built in Windows (on a table on As400) works perfectly with Excel but with PHP it just refuses to work.
I have also Installed iSeries Access for Windows (navigator and the rest).
I need a working answer. THANK YOU VERY MUCH!!
Software/Hardware used:
ASKED:
August 7, 2008 2:40 PM
UPDATED:
June 15, 2009 2:10 AM
Thank you for a speedy reply, but this solution DOES NOT work.
The error is: “Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect”
I’m not sure, but I think I have to declare a connection string somewhere. Something like what Excel gives me upon successful connection to the data on AS400 table:
DRIVER={iSeries Access ODBC Driver};PKG=QGPL/DEFAULT(IBM),2,0,1,0,512;LANGUAGEID=ENU;DFTPKGLIB=QGPL;DBQ=QGPL;SYSTEM=10.69.23.4; Along with pass and username.
And the SQL goes like this: SELECT * FROM “MYLIB”.”DTASRC”
(Where MYLIB is library with my data, and DTASRC is the actual table.
This is really a pain.
“but this solution DOES NOT work”
I beg to differ with you sir. This solution does work. I took this code from an existing PHP script on my system and generously provided it to you for your reference. I have changed the names of system, password, and DB references and simplified syntax for you – since YOU are having the difficulties. If PHP is not working for you, maybe you should try CGI instead.
Good luck to you.
The PHP code looks OK to me..
You may want to look at these two sites, if you have not already:
Regards
Mike
I guess the links didn’t work…
PHP Manual – http://us3.php.net/odbc_connect
and
iSeries connection strings – http://www.connectionstrings.com/?carrier=as400
Regards
Mike
Thank you again for your help but it seems like I have insulted you?
I’m very sorry for that, but this solution really doesn’t work for me.
That’s why I posted what type of error I get and my second question.
Do I have to declare somewhere information about driver that connection is built on?
You stated in your answer : “Try this using the Client Access ODBC Driver. ”
But you didn’t include it in the code? Am I right?
I posted this question because I don’t know how to code, not because I wanted to insult anybody and I was
I’m now helpless but I hope someone will have patience.
not arguing if your solution works or not. If I knew how I would give answers not waiting someone’s mercy to receive ones.
Thank you very much, anyway.
I had the same problem.
I use Windows XP with apache & PHP.
In ODBC Data Source add ODBC DSN (iSeries) in System tab, because the service “apache” runs under “SYSTEM” user and he doesn’t know about the user DSN. Once u have add & configured the DSN it should work.
Good Day,
I’m new to PHP and AS400.
I’m developing a PHP project that connects to AS400.
BTW, what FresnoBob posted works for me. Thanks FresnoBob!!
at first I don’t khow what my iSeriesName but I eventually got it..
@FresnoBob
1. How can I query a file with multiple members?
I tried libraryname.tablename(member) but it doesn’t work
2. How can I know if the file exists in the library
Thanks in advance!!!
Regards,
Benj
Multiple members –
I think that you may have to create an “alias” to the member.
SQL command
CREATE ALIAS library/alias_name FOR library/file(member)
Regards
Mike
@Mcl
Thanks for the reply!!
But I’m afraid format :
library/file(member) is not working.
The format that is accepted is library.file [ period '.' not slash (/) ] and using parentheses is returning an error
I tried:
CREATE ALIAS library.alias_name FOR library.file(member) –> error because of the parentheses
i think
Maybe there’s command (like NMFMT in unix) that will permit using slashes ( / ) rather than period ( . ) so that it will also recognize the slashes??
Anyway, I’ll give it a try again on Monday. I’ll keep you posted
Thanks again.
oopss correction…
Maybe there’s command (like NMFMT in unix) that will permit using slashes ( / ) rather than period ( . ) so that it will also recognize the parentheses??
Well… There are different naming formats..
Try this from a green screen command line.
STRSQL
Then in the SQL screen type CREATE ALIAS and press F4.
Fill in the blanks and press ENTER.
Regards
Mike
Tried STRSQL and indeed the format is:
CREATE ALIAS library/alias_name FOR library/file(member)
But for reason unknown to me, and what FresnoBob provided (which works),
format accepted is:
result=odbc_exec($conn,”SELECT * from library.file where somefield=a value”);
Thanks for the help nway.
It depends on the naming format specified in the ODBC driver setup. When “SQL Naming” is used, you have to use library.file syntax. When “System naming” is specified you have to use the library/file syntax. Try testing this with the “Run SQL scripts” feature of Navigator.
Changed it… tested it… AND USING IT!!!!!
Thanks a lot GreyBeard and MCL also!!