PHP PDO Caching

I searched for the answer to this question, but found nothing. Are the calls in PDO :: prepare () cached or should I cache the result myself, that is, if I do the following

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

will the prepare () command be cached by PDO to quickly get the second, third, etc.? Or is it better to do it yourself, for example.

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

There is a MySQL query cache . But in general, you should definitely save the identifier for the prepared statement and reuse it.

The query cache has disappeared 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/

+4

PDO::prepare() ( SQL-) PDOStatement ( ), , , . PDOStatement prepare() . , , - , SQL-, , prepare(), (, MySQL), PHP.

+4

. MySQL PDO . , .

If you absolutely need to repeat the same query, then yes, you will want to keep this handle. If you use emulated prepared statements, then it does not matter.

+1
source

Some time ago I tried to do this CPDO and it can be used as a standard PDO

0
source

All Articles