简体   繁体   中英

binding parameters and PDO

If the parameters for statement 1 and 2 are identical, do I need to re-bind, or can I do this?

$stmt = $dbh->prepare("SELECT ... thing = :thing ...");
$stmt->bindParam(':thing',$thing);
$stmt->execute();
// do something with data
$stmt = $dbh->prepare("SELECT something else ... thing = :thing ...");
$stmt->execute();

?

Assuming you actually mean:

$stmt = $dbh->prepare("SELECT ... thing = :thing ...");
// ...

No , you are assigning $stmt to a new PDOStatement object, which does not hold the information that was stored in the old object.

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