What is the correct syntax for preparing a query in mysqli for PHP?

When preparing a query in mysqli for PHP, it is important to use placeholders for variables in the query to prevent SQL injection attacks. The correct syntax for preparing a query in mysqli involves using the prepare method on the mysqli object and then binding parameters to the placeholders before executing the query.

// Assuming $mysqli is your mysqli object
$query = $mysqli->prepare("SELECT * FROM users WHERE username = ?");
$username = "john_doe";
$query->bind_param("s", $username);
$query->execute();
$result = $query->get_result();
while ($row = $result->fetch_assoc()) {
    // Process the data
}
$query->close();