php - CakePHP with Stored Procedure -


i trying create stored procedure in cakephp. have created procedure in mysql , created global function in appmodel.php hit procedure. function in appmodel sprocedure. have 2 conditions might have variable return procedure or may have direct resultset eg. have created pagination. though shooting procedure not return result. function require modification?

    public function sprocedure($name = null, $inputparameter = array(), $outputparameter = array()) {         $this->begin();         $parameter = "";         $outputparam = "";         foreach ($inputparameter $params) {             $parameter .= $parameter == "" ? " '$params' " : ", '$params' ";         }          if (count($outputparameter) > 0) {             foreach ($outputparameter $prm) {                 $outputparam .= $outputparam == "" ? " @$prm " : ", @$prm ";             }         }         $parameter = ($outputparam) ? $parameter . ", " . $outputparam : $parameter;         $this->query("call `$name`($parameter);");         $result = $this->query("select $outputparam");         $this->commit();         return $result;     }      $sel_data = $this->articlenews->sprocedure("update_blank", $input_prameter, $output);     debug($sel_data); 

breaking down snippet

$this->query("call `$name`($parameter);"); 

calls stored procedure. lets assume procedure's body simple select

select table.* table; 

this procedure returns result set. take quick @ code provided

 $this->query("call `$name`($parameter);"); 

yes, procedure called result/resource not assigned variable iterate over.

$proc_result = $this->query("call `$name`($parameter);");  $proc_data = array();  if (false !== $proc_result) {     while ($proc_row = mysqli_fetch_array($proc_result))     {         $proc_data[] = $proc_row;      } }  if (!empty($proc_data)) {     //do whatever procedure data } 

related documentation: connector-cpp-tutorials-stored-routines-statements


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -