简体   繁体   中英

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

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?

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

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

You don't. But overriding the variable won't change much - you're assigning a new value to the variable, not editing anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM