gpt4 book ai didi

php - PDO::ATTR_EMULATE_PREPARES(多重绑定(bind)和限制)

转载 作者:行者123 更新时间:2023-11-30 22:24:43 26 4
gpt4 key购买 nike

我刚刚遇到了一个有趣的问题。我需要在参数数组中指定一个变量,但在 SQL 查询中每次出现时都绑定(bind)它,我使用此属性实现了这一点:$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);。但是当我使用它时,另一个带有 LIMIT 的查询不起作用,因为我需要指定 $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); 让它正常工作(所以PDO 将其处理为 INT,而不是 STRING)。我还尝试将 bindValue 函数与 PDO::PARAM_INT 结合使用,但它仍然没有将 LIMIT 值作为 INT 处理。

最佳答案

But when I use this, another query with LIMIT in it doesn't work

您可以即时更改仿真模式,在需要时打开和关闭它。

I also tried to use bindValue function in combination with PDO::PARAM_INT but still It doesn't handle LIMIT value as INT.

确保您明确地将值转换为 int,如 PDO doesn't cast them for PDO::PARAM_INT .

关于php - PDO::ATTR_EMULATE_PREPARES(多重绑定(bind)和限制),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35598397/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com