Solved

Calling AS400 Stored Procedure from PHP with ODBC

Posted on 2010-09-10
3
698 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

706 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

18 Experts available now in Live!

Get 1:1 Help Now