Solved

Calling AS400 Stored Procedure from PHP with ODBC

Posted on 2010-09-10
3
711 Views
Last Modified: 2013-12-13
I have a stored procedure GETSTORES(#####) which requires a five digit account number and returns all stores for that account.  I need to call that stored procedure from php using an ODBC connection.  I can connect to the 400 and query directly but want to use the stored procedure to cut down on traffic.

I can't seem to find anything that works.
0
Comment
Question by:Richardetal
  • 2
3 Comments
 
LVL 27

Expert Comment

by:tliotta
ID: 33650161
I can't seem to find anything that works.

What goes wrong? Is there an error message?

What platform is PHP running on? What i5/OS version is running?

Can you show us a sample of your PHP coding?

Tom
0
 

Author Comment

by:Richardetal
ID: 33661891
iSeries is V5R4
PHP 5.3.1

I'm really at the point of trying to figure out how to construct the command in php.  I've found examples like:
$result=runStoredProc("exec GETSTORES(1550)");  

where GETSTORES(#) is the name of my stored procedure.  

runStoredProc is not recognized.

I'm just not sure how to do it...
0
 

Accepted Solution

by:
Richardetal earned 0 total points
ID: 33779220
Got it working a while ago and thought I'd give an update to help others with the same issue.

The partial code snippet shows the basic connection and how to read the returned data.

I had to use the odbc_result function to read to returned data.




$sql='CALL GETSTORES('.$a.')';
$result = odbc_exec($con, $sql);
echo"<select name=\"sel_store\" id=\"sel_store\" onchange=\"javascript:unhide_style()\">";
      echo"<option  value=\" - Select - \"> - Select - </option>";
      while (odbc_fetch_row($result))
      {
         $sel_string = trim(odbc_result($result,"ABNAME")).", ".trim(odbc_result($result,"ABADDR1")).", ".trim(odbc_result($result,"ABCITY")).", ".trim(odbc_result($result,"ABSTATE"));
         echo"<option value=\"".trim(odbc_result($result,"STORE"))."\">".$sel_string."</option>";
      }
      echo "</select></font></form>";

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now