Example 1 — Get Metadata for Column Zero
Read the first field definition directly and print its name from a sample query.
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
$result = mysqli_query($mysqli, "SELECT id, name FROM products LIMIT 1");
$field = mysqli_fetch_field_direct($result, 0);
echo $field->name, PHP_EOL;
mysqli_free_result($result);
mysqli_close($mysqli); How It Works
- The result has id at index 0 and name at index 1.
- mysqli_fetch_field_direct($result, 0) targets the first column.
- The name property prints as id.
- No field cursor move is needed because the index is explicit.

