Example 1 — Measure Columns of the Current Row
Fetch one row, then print each column length from a fixed sample.
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
$result = mysqli_query($mysqli, "SELECT id, name FROM products WHERE id = 1");
mysqli_fetch_row($result);
$lengths = mysqli_fetch_lengths($result);
echo implode(", ", $lengths), PHP_EOL;
mysqli_free_result($result);
mysqli_close($mysqli); How It Works
- mysqli_fetch_row() loads the current row into the result.
- mysqli_fetch_lengths() returns one integer per column.
- In the sample, id has length 1 and name "Tea Mug" has length 7.
- Call lengths only after a successful row fetch.

