MySQL SP With Cursor

CREATE PROCEDURE `sp_test`( 
in id int, 
in ofset int, 
in lmt int, 
out result int 
)
BEGIN 
DECLARE ch_done INT DEFAULT 0; 

declare program int; 

declare cur cursor for select name from users where ancestor = id LIMIT ofset, lmt; 
DECLARE CONTINUE HANDLER FOR NOT FOUND SET ch_done = 1; 
SET result = 0; 
open cur; 

start_loop: loop 
fetch cur into val; 
IF ch_done = 1 THEN 
LEAVE start_loop; 
END IF; 
SET result = 1; 

 // SQL Queryies with val

end loop; 
close cur; 
select result; 
END

ZF2 : Get Prams into view and Layout

Helper

namespace Application\View\Helper;

/**
 * Description of Params
 *
 * @author Ravi Gupta <ravi.gupta@a3logics.in>
 */
use Zend\Mvc\MvcEvent;
use Zend\Stdlib\RequestInterface;
use Zend\View\Helper\AbstractHelper;

class Params extends AbstractHelper
{
 protected $request;
 protected $event;

public function __invoke($param = null, $default = null)
 {
 if ($param === null) {
 return $this;
 }
 return $this->fromRoute($param, $default);
 }

public function __construct(RequestInterface $request, MvcEvent $event)
 {
 $this->request = $request;
 $this->event = $event;
 }

public function fromPost($param = null, $default = null)
 {
 if ($param === null) {
 return $this->request->getPost($param, $default)->toArray();
 }

return $this->request->getPost($param, $default);
 }

public function fromRoute($param = null, $default = null)
 {
 if ($param === null) {
 return $this->event->getRouteMatch()->getParams();
 }

return $this->event->getRouteMatch()->getParam($param, $default);
 }
}

Register Factory to Module.php

 public function getViewHelperConfig()
 {
 return array(
 'factories' => array(
 'Params' => function (\Zend\ServiceManager\ServiceLocatorInterface $helpers){
 $services = $helpers->getServiceLocator();
 $app = $services->get('Application');
 return new View\Helper\Params($app->getRequest(), $app->getMvcEvent());
 }
 ),
 );
 }