I’m not entirely sure what PHPs PDO queries are doing under the hood. Still new to using them. Here’s my question. Is this safe?
$sth = $dbh->prepare("{some sql statement}");
$sth->execute();
$sth = $dbh->prepare("{an entirely different sql statement}");
$sth->execute();
Could reusing the $sth variable like this cause any issues? I wasn’t sure if i could get into some timing issues or if this was indeed a safe practice.
No,
$sthis a pointer to a statement handler in memory. By assigning a second prepared query to it, the first statement handler has no more pointers to it, and will bee cleaned up by the garbage collector.