Solved

Calling AS400 Stored Procedure from PHP with ODBC

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

786 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