📜  如何使用 get_result 正确的准备语句 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:19.377000             🧑  作者: Mango

代码示例1
prepare($query);

//bind parameters
/*if you already know the value; you can do as follows, or use variable down here 
and assign value after this before executing it*/
$stmt->bind_param("s", $column_name_value_wanted_to_fetch);

//execute the statement; this will return true is success and false on failure
//therefore we can use this as a condition to proceed like this; if($stmt->execute()){}
$stmt->execute();

/*Retrieves a result set from a prepared statement as a mysqli_result object
 This function cannot be used together with mysqli_stmt_store_result().
 Both of these functions retrieve the full result set from the MySQL server.*/
//visit https://www.php.net/manual/en/class.mysqli-result.php to check all methods
$result = $stmt->get_result();

//optional
//to get a count of results you have
$count = $result->num_rows

//this will result an associative array
while ($row = $result->fetch_assoc()) {
    //now you can get details of results you fetched
}