我现在可以通过 PDO 使用 MySQL 的真正准备好的语句吗?
5 年前(真的!)Wez Furlong 是 PDO 的首席开发人员,他写道:
我建议您在使用时使用以下属性 PDO::MYSQL,在当前 PHP 5.1.3 候选版本中可用 快照:
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
这会导致使用 PDO 本机查询解析器而不是 mysql 客户端中的本机准备好的语句 API,并且有效 消除了这些问题。
基本原理参见 http://wezfurlong.org/blog/2006/apr/ using-pdo-mysql/
但是,他无法回答既然 PDO 使用 Mysqlnd 问题是否已经得到解决(至少我认为是这样)。
有谁知道吗?
5 years ago (really!) Wez Furlong was the lead developer of PDO and he wrote this:
I recommend that you use the following attribute when working with
PDO::MYSQL, available in the current PHP 5.1.3 release candidates and
snapshots:$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
This causes the PDO native query parser to be used instead of the
native prepared statements APIs in the mysql client, and effectively
eliminates those problems.
Rationale is given at http://wezfurlong.org/blog/2006/apr/using-pdo-mysql/
However, he could not answer if the problems have been remedied now that PDO is using Mysqlnd (at least I assume it is).
Does anyone know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,如果您将
ATTR_EMULATE_PREPARES
设置为false
(或0
),它将使用真正的准备好的语句。有点像。它仍然具有所有后备逻辑。因此,如果服务器的准备失败,mysqli::prepare 就会失败,但 PDO 不会,因为它将回退到模拟准备。这样做的原因是,PDO 可以在不支持准备的 MySQL 版本上使用准备好的语句,以及不支持准备的 for 语句(例如 ALTER)。
因此,只要 MySQL 允许,它就会使用真正的准备好的语句(同样,只有当
ATTR_EMULATE_PREPARES
为 false 时)...Yes, if you set
ATTR_EMULATE_PREPARES
tofalse
( or0
) it will use real prepared statements.Sort of. It still has all of the fallback logic. So while mysqli::prepare would fail if the prepare from the server failed, PDO will not as it will fall back to emulating the prepare. The reason for this is so that PDO can use prepared statements on versions of MySQL that don't support it, as well as for statements (such as
ALTER
) which don't support preparation.So it will use real prepared statements whenever MySQL will let you (again, only if
ATTR_EMULATE_PREPARES
to false)...