Reputation: 397
Regarding "prepared statements" in php,
I have found here in the official documentation of php this piece of code that I don´t understand.
/* execute statement */
$stmt->execute();
/* bind result variables */
$stmt->bind_result($name, $code);
I had always seen the "binding" first and then, the "execution".
Could anybody tell me why in this case, is the other way around?
Thanks.
Upvotes: 3
Views: 259
Reputation: 768
Binding "parameters" and binding "results" are two different things.
You have to bind parameters before execution because parameters are going to be used during execution.
Yet, you have the result in $stmt object after execution, and if you want to use columns from the result, you bind results to variables.
So here are the steps:
bind parameters to $stmt object
$stmt->bind_param(...)
execute prepared statement
$stmt->execute()
bind columns from the result to variables
$stmt->bind_result(...)
Upvotes: 1