Example 1 — Read One Associative Row
Fetch the first user row and print two columns. Output is a fixed demo sample.
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
$result = mysqli_query($mysqli, "SELECT id, email FROM users WHERE id = 1");
$row = mysqli_fetch_assoc($result);
echo $row["id"], " ", $row["email"], PHP_EOL;
mysqli_free_result($result);
mysqli_close($mysqli); How It Works
- A connection is opened to the demo shop database.
- The SELECT asks for one user by id.
- mysqli_fetch_assoc() returns that row as an associative array.
- We print id and email from the sample row.

