Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know if a Prepared Statement is being Cached?

Tags:

php

mysql

pdo

I have been reusing the same variable $stmt in my PHP script to write prepared statements:

$stmt = $dbh->prepare("SELECT column_A FROM Table1 WHERE id=?");
$stmt->bindValue(1, $id, PDO::PARAM_INT);
$stmt->execute();
....

$stmt = $dbh->prepare("UPDATE Table2 SET column_B=? WHERE column_A=?");
$stmt->bindValue(1, $name);
$stmt->bindValue(2, $column_A);
$stmt->execute();

My question is, how do I know if the two statements are being written to cache and that the second statement did not overwrite the first statement though both statements are sharing the same variable name?

like image 725
Question Overflow Avatar asked Nov 28 '11 15:11

Question Overflow


1 Answers

Statements are prepared by the database engine and not PHP, see:

  • http://dev.mysql.com/doc/refman/5.1/en/prepare.html

So reusing the same variable name in PHP won't invalidate the MySQL prepare "cache".

like image 174
Alix Axel Avatar answered Sep 25 '22 06:09

Alix Axel