0

自 Doctrine DBAL 2.13 发布以来,已按此处所述添加了弃用。

虽然获取结果的旧方式是这样的:

$statement->execute();
while (($row = $statement->fetch()) !== false) {
}

新方法是这样的:

$result = $statement->execute();
while (($row = $result->fetchAssociative()) !== false) {
}

我想更新我的代码以准备为学说/dbal 3.0 准备,但$statement->execute()不返回结果集,而只是返回一个布尔值,因此没有什么可迭代的,即使发行说明指出:

DBAL 3.0 从 Statement API 中提取所有 fetch-methods 并将它们移动到从 Statement::execute 返回的新 Result API。我们已将此 A​​PI 向后移植到 2.13

那么这是否意味着反向移植失败或者我错过了什么?

4

1 回答 1

1

更新学说/dbal 2.13.1(2021 年 4 月发布)并使用:

$result = $statement->executeQuery();
while (($row = $result->fetchAssociative()) !== false) {
}

请注意,executeQuery() 应该用于获取 Result 对象,因为 execute() 现在也已弃用。(发行说明中也缺少这点)

于 2021-04-20T06:25:36.660 回答