Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calling AS400 Stored Procedure from PHP with ODBC

Posted on 2010-09-10
3
Medium Priority
?
778 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

971 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