PHP PDO Caching

后端 未结 4 484
Happy的楠姐
Happy的楠姐 2021-01-18 03:48

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

相关标签:
4条回答
  • 2021-01-18 04:05

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

    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-support-for-the-query-cache/

    0 讨论(0)
  • 2021-01-18 04:11

    Two subsequent calls to PDO::prepare() (even with the same SQL query) should return two different PDOStatement (or handles) to avoid collisions, especially between previous and current bindings you may apply to it. The cost of creating a PDOStatement with prepare() is low anyway. What you may want cached are the results returned from the same SQL query, either raw or built by prepare() and this is a feature of your DBMS (MySQL for instance), not PHP.

    0 讨论(0)
  • 2021-01-18 04:19

    It depends on your database driver. With MySQL, PDO will create a native prepared statement by default. You can disable it, if you want to use an actual query cache.

    If you absolutely must execute the same query repeatedly, then yes, you'll want to keep that handle around. If you're using emulated prepared statements, then it makes no difference at all.

    0 讨论(0)
  • 2021-01-18 04:28

    Some time ago I've tried do it CPDO and it can be used as the standard PDO

    0 讨论(0)
提交回复
热议问题