无法从CakePHP 3.4中的存储过程访问多个结果行集

问题描述 投票:0回答:1

我正在尝试访问从CakePHP 3.4项目中的存储过程返回的多个结果集。这是我的代码:

$stmt = $db->execute("call mydatasp($paramlist)");
    $result = array();                     
    try{
            do
            {
                $rowset = $stmt->fetchAll('assoc');
                $result[]=$rowset;
            } while($stmt->nextRowset());
        }
        catch(Exception $e){}

我进行了很多搜索,并且也通过此链接进行了搜索,但未找到任何有用的数据。 How to call PDOStatement::nextRowset() in Cakephp 3

我该怎么做?

php mysql cakephp pdo cakephp-3.0
1个回答
0
投票
$connection = ConnectionManager::get('default');

$sql = "CALL test()"; // name of stored procedure

$rowSet = 1; //default value is 1,change according to stored procedure result set to access multiple result

$stmt = $connection->execute($sql)->getInnerStatement()->getInnerStatement();

for ($i = 0; $i < $rowSet; $i++) {
    if($i > 0)
        $stmt->nextRowset();
    $response[] = $stmt->fetchAll(PDO::FETCH_ASSOC);
}

print_r($response);

假设存储过程test()返回4个结果集,那么您需要修改$rowSet = 4的值,否则默认值为1

© www.soinside.com 2019 - 2024. All rights reserved.