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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -