php - Can i reuse the prepared statement object -
in many occasions i'm using more 1 prepared statements, so
$conn = connect('read'); // connect database $q = 'select ...'; $stmt = $conn->prepare($q); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($a, $b, $c); $stmt->free_result(); $stmt->close(); $q = 'select ...'; $stmt2 = $conn->prepare($q); $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($a, $b, $c, $d, $e, $f...); $stmt2->free_result(); $stmt2->close(); $conn->close(); // close db connection
and it's mess trying figure out number give stmt variable...
so, can reuse stmt object on , on once close using stmt->close() way don't need keep trace of index give variable stmt ?
is practice or bad practice?
yes, reuse variable right , quite practice.
aside that, don't think it's quite repetitive use code again , again? using function, make things like
$row = function('select ...', $params); list($a, $b, $c) = function('select ...', $another);
Comments
Post a Comment