Calling a Stored Procedure

Advantage Database Server v8.1: A Developer’s Guide

by Cary Jensen and Loy Anderson

  © 2007 Cary Jensen and Loy Anderson. All rights reserved.

  Previous topic Next topic  

This final example demonstrates the execution of a stored procedure using PHP. Actually, as you can see from these statements, executing a stored procedure is no different than any other type of parameterized query. After a call to ads_prepare, an array is created to hold the parameter values, after which it is passed as an argument to ads_execute. Once again, the ads_result_all function is used to render an HTML table from the query result set. The following PHP commands are located in the storedproc.php script:

<?
$rConn = ads_connect( "DataDirectory=\\\\server\\share\\".
 "adsbook\\DemoDictionary.add;ServerTypes=2;",
 "adsuser", "password" );
$rStmt = ads_prepare( $rConn,
 "EXECUTE PROCEDURE SQLGet10Percent ( ? )" );
$aParams = array( 1 => $_GET[ "custnumber" ] );
$rResult = ads_execute( $rStmt, $aParams );
if ( $rResult == FALSE )
  {
  echo ads_errormsg( $rConn ) . "<br>\n";
  }
else
  {
  ads_result_all( $rStmt );
  }
ads_close( $rConn );
?>