Current Location: Home> Function Categories> mysqli_result::field_seek

mysqli_result::field_seek

(mysqli_field_seek) Set the result pointer to the specified field offset
Name:mysqli_result::field_seek
Category:MySQLi
Programming Language:php
One-line Description:Move the result set pointer to the specified field offset

Function name: mysqli_result::field_seek()

Applicable version: PHP 5, PHP 7

Function description: the mysqli_result::field_seek() method is used to move the pointer of the result set to the specified field offset.

Syntax: bool mysqli_result::field_seek(int $field_offset)

parameter:

  • $field_offset: An integer representing the offset of the field to be moved to. Field offsets are counted from 0.

Return value:

  • Return true if the pointer is successfully moved.
  • Returns false if the specified field offset is out of range.

Example:

connect_errno) { echo "Connection failed: " . $mysqli->connect_error; exit(); } // Execute the query $query = "SELECT id, name, age FROM users"; $result = $mysqli->query($query); // Check the query result if ($result) { // Move the pointer to the second field $result->field_seek(1); // Get the information of the current field $field = $result->fetch_field(); // Print the field information echo "Field name: " . $field->name . "
"; echo "field type: " . $field->type . "
"; echo "field length: " . $field->length . "
"; } else { echo "Query failed: " . $mysqli->error; } // Close the connection $mysqli->close(); ?>

In the above example, we first create a MySQLi connection and then execute a query statement. Next, we use the mysqli_result::field_seek() method to move the pointer of the result set to the second field (name field). Then, we use the fetch_field() method to get the information of the current field and print it out. Finally, we closed the database connection.

Note: Before using the mysqli_result::field_seek() method, you must execute a query statement and obtain the result set object.

Similar Functions
Popular Articles