Support server side prepared statements with PDO?

旧城冷巷雨未停 提交于 2019-11-29 13:55:56

Some PDO drivers don't support native prepared statements, so PDO performs emulation of the prepare. It also lets you manually enable this emulation.

Check the PDO::ATTR_EMULATE_PREPARES attribute. It's poorly documented in the current PDO manual. By poorly documented, I mean that it appears only in comments on the site, not in the manual itself.

Generally you want to use native prepared statements whenever possible. In the case of MySQL, if you are taking advantage of the query cache, you might actually want to disable native prepared statements in PDO! The MySQL manual has more information, but the short version is that versions prior to 5.1.17 don't run prepared statements through the query cache, and subsequent versions only use the query cache under certain specific (but common) conditions.

(Some people recommend turning off the query cache entirely. Using large cache sizes can actually be a major performance hit.)

By default, PDO_MYSQL emulates the prepared statements. To use the native server-side prepared statements, one should explicitely set

$PDO->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!