Solved

Calling AS400 Stored Procedure from PHP with ODBC

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

821 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