I don't think you need either, really. You should be able to use mysqli_stmt_get_result to get a result set and then use your regular result set functions (i.e. mysqli_fetch_assoc)
mysqli procedural prepared statements
-
30-06-2022 - |
Question
I am trying to pass from classic mysql to mysqli..
I have chosen to use the procedural way instead of the object oriented, although I find far more examples in the object oriented way..
I need make a part of code where I would check if a value is already within a DB record in terms of validation.
I have come to this part of code, it does work, but I am not quite sure, if I am missing some part, or if I have included unnecessary statements..
$con = mysqli_connect("localhost","username","password","db");
// Check connection
if (mysqli_connect_errno($con)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$stmt = mysqli_prepare($con, "SELECT email FROM table WHERE email= ? ");
mysqli_stmt_bind_param($stmt, 's', $email);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($result);
mysqli_stmt_store_result($stmt);
if (mysqli_stmt_num_rows($stmt) > 0) {
some code
}
else {
some other code
}
I am most concerned about these two lines
mysqli_stmt_bind_result($result);
mysqli_stmt_store_result($stmt);
especially the
mysqli_stmt_bind_result($result);
feels like that is not necessary while
mysqli_stmt_store_result($stmt);
seems to be necessary according to php.net seems necessary for temporary storage..
No correct solution
OTHER TIPS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow