Function name: mysqli_stmt::data_seek()
Function Description: This function is used to move the pointer in the result set to the specified line number.
Function usage: bool mysqli_stmt::data_seek(int $offset)
parameter:
Return value:
Sample code:
<?php // 假设已经连接到MySQL数据库,并且准备了一个查询语句// 创建预处理语句对象$stmt = $mysqli->prepare("SELECT id, name, age FROM users"); // 执行预处理语句$stmt->execute(); // 绑定结果集中的列到变量$stmt->bind_result($id, $name, $age); // 移动结果集的指针到第三行(假设有足够多的行) $stmt->data_seek(2); // 获取第三行的数据$stmt->fetch(); // 输出第三行的数据echo "ID: " . $id . ", Name: " . $name . ", Age: " . $age; // 关闭预处理语句和数据库连接$stmt->close(); $mysqli->close(); ?>
In the above example code, we assume that we have connected to the MySQL database and have prepared a query statement. First, we create a preprocessing statement object $stmt and execute the preprocessing statement. We then use the bind_result() function to bind the columns in the result set to the variables $id, $name, and $age. Next, we use the data_seek() function to move the pointer of the result set to the third row. Finally, we use the fetch() function to get the data at the current pointer position and output it to the screen.
Note that the line numbers in the above example code are counted from 0, that is, the line numbers of the first line are 0, the line numbers of the second line are 1, and so on.