我一直在寻找这个问题的答案,但没有在任何地方找到它。是否缓存了对 PDO::prepare() 的调用,或者我应该自己缓存结果,即如果我执行以下操作
function foo () {
$handle = PDO::prepare(...);
/* do stuff with the handle */
}
prepare() 语句是否会被 PDO 缓存,以便在第二次、第三次等时快速检索?还是自己做比较好,例如
function foo() {
static $handle = null;
if (!$handle) {
$handle = PDO::prepare(...);
}
/* do stuff with the handle */
}
最佳答案
有 MySQL query cache .但总的来说,您绝对应该保留准备好的语句的标识符并重新使用它。
查询缓存在 MySQL 8.0 版本中消失了,参见
https://dba.stackexchange.com/questions/217577/why-mysql-remove-query-cache-in-8-0-version
https://mysqlserverteam.com/mysql-8-0-retiring-support-for-the-query-cache/
关于PHP PDO 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1884576/