Example 1 — Real Query Then Store Result
Split send + fetch for a SELECT, with fixed sample output.
<?php
$mysqli = mysqli_connect("localhost", "demo_user", "demo_pass", "app_db");
if (!mysqli_real_query($mysqli, "SELECT name FROM users LIMIT 1")) {
echo mysqli_error($mysqli), PHP_EOL;
exit;
}
$result = mysqli_store_result($mysqli);
$row = mysqli_fetch_assoc($result);
echo $row["name"], PHP_EOL;
mysqli_free_result($result);
mysqli_close($mysqli); How It Works
- real_query sends the SELECT.
- store_result pulls a buffered mysqli_result.
- fetch_assoc reads the sample name.
- Free the result afterward.

