PHP PDO缓存 [英] PHP PDO Caching

查看:133
本文介绍了PHP PDO缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找答案,但是在任何地方都找不到.是缓存对PDO :: prepare()的调用,还是我自己缓存结果,即是否执行以下操作

I've been looking for an answer to this but haven't found it anywhere. Are calls to PDO::prepare() cached, or should I cache the result myself, i.e. if I do the following

function foo () {
  $handle = PDO::prepare(...);
  /* do stuff with the handle */
}

PDO是否会将prepare()语句缓存起来,以便快速地进行第二次,第三次等等的检索?还是最好自己动手做,例如

will the prepare() statement be cached by PDO so that it's quickly retrieved the second, third etc. times? Or is it better to do it myself, e.g.

function foo() {
  static $handle = null;
  if (!$handle) {
    $handle = PDO::prepare(...);
  }
  /* do stuff with the handle */
}

推荐答案

MySQL查询缓存.但是总的来说,您绝对应该保留准备好的语句的标识符并重新使用它.

There is the MySQL query cache. But in general you should definitely keep the identifier for the prepared statement and re-use it.

MySQL 8.0版中的查询缓存已消失,请参见

The query cache is gone in MySQL version 8.0, see

https://dba.stackexchange.com /questions/217577/why-mysql-remove-query-cache-in-8-0-version

https://mysqlserverteam.com/mysql-8-0-retiring-for-the-query-cache/

这篇关于PHP PDO缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆