雖然文件說明您必須提供 0 到 count - 1 之間的數字,但實際上您可以提供負數,它似乎會被轉換為正數(例如在 abs() 中)。
例如
<?php
$db = new mysqli('localhost', 'test', 'password', 'schema');
$db->multi_query("
SELECT * FROM
(
SELECT 1 as 'position'
UNION SELECT 2 as 'position'
UNION SELECT 3 as 'position'
UNION SELECT 4 as 'position'
UNION SELECT 5 as 'position'
) as rows");
$result = $db->store_result();
for ($i = 0; $i < $result->num_rows; $i++)
{
$offset = $i;
$result->data_seek($offset);
var_dump("Seek offset is: {$offset}", $result->fetch_object());
}
for ($i = 0; $i < $result->num_rows; $i++)
{
$offset = -$i;
$result->data_seek($offset);
var_dump("Seek offset is: {$offset}", $result->fetch_object());
}