I'm just getting familiar with prepared statements. I have a query working, with a loop to bind the results into something I can work with easier.
Now, I'd like to add another query and I'm not sure of the correct syntax
/* Create a new mysqli object with database connection parameters */
$mysqli = new mysqli($hostname_db, $username_db, $password_db, $database_db);
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
/* Create a prepared statement */
if($stmt = $mysqli -> prepare("SELECT * FROM table WHERE id = ?")) {
/* Bind parameters, s - string, b - blob, i - int, etc */
$stmt -> bind_param("i", $rid);
$stmt -> execute();
/* USE loop to bind result and fetch */
$meta = $stmt->result_metadata();
while ($field = $meta->fetch_field()) {$parameters[] = &$row[$field->name];}
call_user_func_array(array($stmt, 'bind_result'), $parameters);
while ($stmt->fetch()) {
foreach($row as $key => $val) { $x[$key] = $val;
}
$results[] = $x;
}
/* Close statement */
$stmt -> close();
------------------>SHOULD I PUT ANOTHER QUERY HERE?
}
------------------>OR SHOULD I PUT ANOTHER QUERY HERE INSTEAD?
/* Close connection */
$mysqli -> close();
----------------->Or, should I put it here
//END mysqli query method
I'm not sure of which of the three positions is the best place/best practice. I could get it done with trial and error, but I'd like to know what is the best practice and I can't seem to locate a clear answer.
Thanks in advance.