Help! How to execute a stored procedure in Phalcon? thanks.
This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.
|
Oct '15 |
4 |
1342 |
0 |
$sql = "CALL storedProcedure();";
$myModel = new MyModel();
$result = $myModel->getReadConnection()->query($sql)->fetch(); // Or fecthAll()
it's working for me, But data is reponse repeating data as below.
[{"id":"248","0":"248","name":"Sameer","1":"Sameer","email":"[email protected]","2":"[email protected]"}]
You can create a function to call stored procedure in your model Here is an example: /*
Tran.. thanks i did it another way. Created method in Model and called the same from controller Model:
public static function callMyPro($params)
{
// A raw SQL statement
$sql = "CALL my_procedure($params);";
// Base model
$robot = new MyModel();
// Execute the query
return new Resultset(null, $robot, $robot->getReadConnection()->query($sql));
}
Controller: $myModel = new MYModel(); $results = $myModel->callMyPro($params)->toArray();
And it works for me.
Thanks