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?
Source: Tips4all
Statements are prepared by the database engine and not PHP, see:
ReplyDeletehttp://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".
You don't. But overriding the variable won't change much - you're assigning a new value to the variable, not editing anything.
ReplyDelete