Example 1 — Read the First Column of Each Row
Fetch product names from a single-column SELECT. Sample names are fixed for the tutorial.
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
$result = mysqli_query($mysqli, "SELECT name FROM products ORDER BY id LIMIT 3");
while (($name = mysqli_fetch_column($result)) !== null) {
echo $name, PHP_EOL;
}
mysqli_free_result($result);
mysqli_close($mysqli); How It Works
- The SELECT returns only the name column.
- mysqli_fetch_column() with no second argument reads column 0.
- The loop continues until the function returns null.
- Three sample product names are printed.

