What is the difference between using execute_query[1] or using the prepare then execute [2] and when do we use the bind parameter and why? like in example [2] we already gave the variables within the execute so when is the bind parameter more useful?
[1]
$stmt = $db->execute_query($Update, [$Date, $Email]);
[2]
$stmt = $db->prepare("INSERT INTO Users (Username, Email, Password, Creation_Date, VIP, Admin) VALUES (?,?,?,?,?,?)");
$stmt->execute([
$Username,
$Email,
$Password,
$Creation_date,
$VIP,
$Admin,
]);
Please give an in your own words explanation as i have hard time understanding documentations and they aren’t always clear!
Thanks in advance!
>Solution :
execute_query() is simply a shortcut that allows you to combine prepare(), bind_param(), execute(), and get_result() into a single call.
Since you don’t have a mysqli_stmt object, status information about the query will be put into the $db object. For example, instead of $stmt->affected_rows you use $db->affected_rows.