Example 1 — Re-read the First Row
Fetch once, seek to 0, fetch again. Sample output when connected to a demo database.
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
$result = mysqli_query($mysqli, "SELECT name FROM products ORDER BY id LIMIT 3");
$row = mysqli_fetch_assoc($result);
echo "first pass: ", $row["name"], PHP_EOL;
mysqli_data_seek($result, 0);
$row = mysqli_fetch_assoc($result);
echo "after seek: ", $row["name"], PHP_EOL;
mysqli_free_result($result);
mysqli_close($mysqli); How It Works
- query() returns a buffered mysqli_result.
- The first fetch_assoc() reads row 0.
- data_seek(0) moves the cursor back to the start.
- The second fetch reads the same first row again.

