【发布时间】:2018-08-24 10:02:02
【问题描述】:
我正在尝试访问从我的 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
我该怎么做?
【问题讨论】:
-
那么在您链接的问题的答案中使用代码有什么问题?
-
@ndm 感谢您的快速回复。我已经尝试了代码,但它只给了我第一个结果集而不是全部。这是我的代码。在 $result 数组中,我只得到第一个结果集 - try{ do { $rowset = $stmt->fetchAll('assoc'); $结果[]=$行集; } while($stmt instanceof StatementDecorator); }
-
我明白了,你不会这样使用它。您可以使用它从从
execute()调用收到的语句装饰器 ($stmt) 中提取最里面的 PDO 语句,然后您可以使用原始的do...while循环对其进行迭代。 -
我已经更新了my answer 并提供了一个更清晰的示例。
-
这表明你没有使用我回答中的代码。
标签: php mysql cakephp pdo cakephp-3.0