0

I want to call my stored procedure which accept only one integer input parameter and return multiple rows in cakephp framework.

Stored Procedure:

PROCEDURE `Salary`(IN sysid int )
BEGIN
SELECT name, lastName, Salary, Month From SalaryData 
where Userid = sysid;
END

Model.PHP:

<?php
 class SalaryModel extends AppModel
 {
   public function sProcedure($testId) 
{
    $result=$this->query("CALL Salary($testId);");
    return $result;
}
 }?>

My Controller code is:

public function Procdata($testId) {
    $result=$this->Systemstate->sProcedure($testId);
 }

Now, Can anyone suggests me how to display the content of query in "view.ctp" ??

I hope my model is correct.

Thanks in advance

2 Answers2

1

MySQL stored procedure does not usually return some result. You need to develop FUNCTION instead to return some value. Read more here.

Community
  • 1
  • 1
Bogdan Burym
  • 5,482
  • 2
  • 27
  • 46
0

There are various methods to call stored procedures in cakephp. but the best way is to execute it as a query instead of baking it as a model, because up to my search there is no way to build or bake complex stored procedures.

So, this way I solved my issue:

My Controller code is:

    public function Procdata($testId) {
    $result=$this->Systemstate->sProcedure($testId);
    $this->set('data',$result);
 }

My Display Section View.CTP

   print_r($data);