MSSQL and DB, Zend as PHP Framework,
I am using this way to call SP with I/P Parameters and to get O/p Parameters.
It seems I am writing SQL code in PHP.
Any other good approaches?
$str1 = "DECLARE @Msgvar varchar(100); DECLARE @last_id int;
exec DispatchProduct_m_Ins $DispatchChallanId,'$FRUNo',$QTY,$Rate,$Amount,
".$this->cmpId.",".$this->aspId.",".$this->usrId.",@Msg = @Msgvar OUTPUT,@LAST_ID = @last_id OUTPUT;
SELECT @Msgvar AS N'@Msg',@last_id AS '@LAST_ID'; ";//Calling SP
$stmt = $db->prepare($str1);
$stmt->execute();
$rsDispProd = $stmt->fetchAll();
$DispatchProductId = $rsDispProd[0]["@LAST_ID"];//get last ins ID as O/p Parameter
Best Answer
Unfortunately I am not using the Zend Framework but I did good experiences using a dedicated class for the stored procedure stuff which handles the parameters, do the queries and is dealing with the results.
My Model extends the class SPData and adds the methods according to the given SPs. PHP PDO with MS SQL Drivers are used to call the available stored procedures.
Example using a SP to get an array as a result:
Example using a SP to get a speciefed output parameter as a result:
Source code of the SPData Class: