Example 1 — Read the First Field Name
Fetch metadata for the first column and print its name from a sample result.
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
$result = mysqli_query($mysqli, "SELECT id, name FROM products LIMIT 1");
$field = mysqli_fetch_field($result);
echo $field->name, PHP_EOL;
mysqli_free_result($result);
mysqli_close($mysqli); How It Works
- The SELECT defines two columns: id and name.
- mysqli_fetch_field() returns metadata for the first column.
- The name property is "id" in this sample.
- A later call would return the name column next.

