Example 1 — Count Columns After a SELECT
Run a three-column query and print mysqli_field_count() from a fixed demo.
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
mysqli_query($mysqli, "SELECT id, name, price FROM products LIMIT 1");
echo mysqli_field_count($mysqli), PHP_EOL;
mysqli_close($mysqli); How It Works
- The SELECT lists three columns.
- mysqli_field_count() reads that count from the connection.
- The sample prints 3.
- You can also check $result->field_count if you kept the result handle.

