Discussion:
Using CL from PHP
(too old to reply)
Vmrincon
2007-04-18 11:02:27 UTC
Permalink
Hi everybody!

I have a problem related to a connection to a AS400 from a PHP
program.

I am migrating a system that was built in Visual Basic and used to
call a CL this way:

ADOCmd.CommandText = "{{call /QSYS.LIB/EXAMPLE.LIB/
EXAMPLECL.PGM(?,?)}}"

And via ADO worked perfectly...

But now (and this is my real problem) when I try to do the same via
PHP

$dbh = odbc_connect("Driver={Client Access ODBC Driver (32-
bit)};System=ipaddress",'user','pwd');
$sql = 'CALL /QSYS.LIB/EXAMPLE.LIB/EXAMPLECL.PGM(?,?)';
$stmt = odbc_prepare($dbh, $sql);

I get this error:

Warning: odbc_prepare() [function.odbc-prepare]: SQL error: [IBM]
[Drivrutinen iSeries Access ODBC][DB2 UDB]SQL0104 - Token / was not
valid. Valid tokens: : <IDENTIFIER>, SQL state 37000 in SQLPrepare in

and the connection fails. I think it must be something about syntaxis
when using "/". Does anybody have any idea about how could I solve
this? Or does anyone know some good reference to use CL programs from
PHP

Thanks a lot!!!
m***@thomsonlearning.com
2007-04-18 11:58:30 UTC
Permalink
I haven't done anything with ADO but it seems to me that ADOCmd
actually understands how to call programs. In your PHP code, you're
trying to call the same program using SQL. This is doable but what you
need to do is create a stored procedure definition on the AS/400 and
call that instead. You can create the stored procedure definition
using either interactive SQL (STRSQL and you'd use the CREATE
PROCEDURE statement) or iSeries Navigator. Once that's done, you would
then change your CALL statement to use the stored procedure name
instead of the actual program name. If you are running PHP on your AS/
400, there may be some documentation on Zend's site about doing this.
I know they did some integration work with IBM to provide enhanced
functionality but I don't know what all they did.

Matt
Post by Vmrincon
Hi everybody!
I have a problem related to a connection to a AS400 from a PHP
program.
I am migrating a system that was built in Visual Basic and used to
ADOCmd.CommandText = "{{call /QSYS.LIB/EXAMPLE.LIB/
EXAMPLECL.PGM(?,?)}}"
And via ADO worked perfectly...
But now (and this is my real problem) when I try to do the same via
PHP
$dbh = odbc_connect("Driver={Client Access ODBC Driver (32-
bit)};System=ipaddress",'user','pwd');
$sql = 'CALL /QSYS.LIB/EXAMPLE.LIB/EXAMPLECL.PGM(?,?)';
$stmt = odbc_prepare($dbh, $sql);
Warning: odbc_prepare() [function.odbc-prepare]: SQL error: [IBM]
[Drivrutinen iSeries Access ODBC][DB2 UDB]SQL0104 - Token / was not
valid. Valid tokens: : <IDENTIFIER>, SQL state 37000 in SQLPrepare in
and the connection fails. I think it must be something about syntaxis
when using "/". Does anybody have any idea about how could I solve
this? Or does anyone know some good reference to use CL programs from
PHP
Thanks a lot!!!
Vmrincon
2007-04-19 11:47:22 UTC
Permalink
Thanks a lot for your answer Matt, but the problem is that I am not
the administrator of the AS400, I just got that call /QSYS.LIB/
EXAMPLE.LIB/EXAMPLECL.PGM(?,?) from the ones that administrate it and
of course they are not so happy about the idea of changing some
configuration just because of me...

Anyway thanks for your answer!
Post by m***@thomsonlearning.com
I haven't done anything with ADO but it seems to me that ADOCmd
actually understands how to call programs. In your PHP code, you're
trying to call the same program using SQL. This is doable but what you
need to do is create a stored procedure definition on the AS/400 and
call that instead. You can create the stored procedure definition
using either interactive SQL (STRSQL and you'd use the CREATE
PROCEDURE statement) or iSeries Navigator. Once that's done, you would
then change your CALL statement to use the stored procedure name
instead of the actual program name. If you are running PHP on your AS/
400, there may be some documentation on Zend's site about doing this.
I know they did some integration work with IBM to provide enhanced
functionality but I don't know what all they did.
Matt
Post by Vmrincon
Hi everybody!
I have a problem related to a connection to a AS400 from a PHP
program.
I am migrating a system that was built in Visual Basic and used to
ADOCmd.CommandText = "{{call /QSYS.LIB/EXAMPLE.LIB/
EXAMPLECL.PGM(?,?)}}"
And via ADO worked perfectly...
But now (and this is my real problem) when I try to do the same via
PHP
$dbh = odbc_connect("Driver={Client Access ODBC Driver (32-
bit)};System=ipaddress",'user','pwd');
$sql = 'CALL /QSYS.LIB/EXAMPLE.LIB/EXAMPLECL.PGM(?,?)';
$stmt = odbc_prepare($dbh, $sql);
Warning: odbc_prepare() [function.odbc-prepare]: SQL error: [IBM]
[Drivrutinen iSeries Access ODBC][DB2 UDB]SQL0104 - Token / was not
valid. Valid tokens: : <IDENTIFIER>, SQL state 37000 in SQLPrepare in
and the connection fails. I think it must be something about syntaxis
when using "/". Does anybody have any idea about how could I solve
this? Or does anyone know some good reference to use CL programs from
PHP
Thanks a lot!!!
Dr.UgoGagliardelli
2007-04-19 12:20:14 UTC
Permalink
Post by Vmrincon
Thanks a lot for your answer Matt, but the problem is that I am not
the administrator of the AS400, I just got that call /QSYS.LIB/
EXAMPLE.LIB/EXAMPLECL.PGM(?,?) from the ones that administrate it and
of course they are not so happy about the idea of changing some
configuration just because of me...
Anyway thanks for your answer!
Maybe you didn't got what he meant.
The CALL statement via SQL has the form: CALL db_schema.db_procedure
Knowing this you shoul agree that the sintax
CALL /QSYS.LIB/EXAMPLE.LIB/EXAMPLECL.PGM(?,?)
do not follow the above rule.
If EXAMPLE.EXAMPLECL is a db registered procedure, you should use
CALL EXAMPLE.EXAMPLECL(?,?) sintax.
To check whether the procedure is registered try the following sql
statement:
SELECT char(SPECSCHEMA, 20), char(SPECNAME, 20), char(RTNNAME, 20),
RTNTYPE, EXTNAME FROM QSYS2.SYSROUTINE
WHERE RTNTYPE = 'PROCEDURE' and EXTNAME like 'EXAMPLE/EXAMPLECL%'

note that SPECNAME and RTNNAME can be the same or different, so if found
the names to use must combined as: SPECSCHEMA.RTNNAME the db will select
the correct SPECNAME basing on procedure or function arguments and data
tipes.
If not found you should have the db admin register the program as a
stored procedure with "create procedure" sql statement.
--
Dr.Ugo Gagliardelli,Modena,ItalyCertifiedUindoscrasherAñejoAlcoolInside
Spaccamaroni andate a cagare/Spammers not welcome/Spammers vão à merda
Spamers iros a la mierda/Spamers allez vous faire foutre/Spammers loop
schijten/Spammers macht Euch vom Acker/Spamerzy wypierdalac'
Tom Liotta
2007-04-21 08:48:14 UTC
Permalink
Post by m***@thomsonlearning.com
I haven't done anything with ADO but it seems to me that ADOCmd
actually understands how to call programs. In your PHP code, you're
trying to call the same program using SQL. This is doable but what you
need to do is create a stored procedure definition on the AS/400 and
call that instead.
Note that an actual creation of a stored procedure definition is only
required _if_ you want values _returned_ in parameters. If no values are
returned (or generally even if you simply don't care about accessing
them), you can execute the SQL CALL _as if_ a stored procedure had been
created.
--
Tom Liotta
http://zap.to/tl400
Continue reading on narkive:
Loading...