【问题标题】:Doctrine DBAL 2.13 $statement->execute() returns bool (instead of Result)Doctrine DBAL 2.13 $statement->execute() 返回 bool(而不是 Result)
【发布时间】:2021-06-27 11:24:10
【问题描述】:

自 Doctrine DBAL 2.13 发布以来,已添加弃用,如 here 所述。

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

$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 返回的新结果 API。我们 已将此 A​​PI 向后移植到 2.13

这是否意味着反向移植失败或我遗漏了什么?

【问题讨论】:

标签: php doctrine doctrine-dbal


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-28
    • 2020-09-11
    • 2016-09-20
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 2016-01-10
    相关资源
    最近更新 更多