English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_field_seek() function sets the field pointer to the offset of the specified field.
A PHP result object (mysqli_result class) represents the MySQL result returned by SELECT or DESCRIBE or EXPLAIN queries.
The mysqli_field_seek() function accepts a result object and an integer value representing the field number as parameters, and moves the field search of the given result object to the specified field.
mysqli_field_seek($result, $field);
Serial number | Parameters and descriptions |
---|---|
1 | result(Required) This is an identifier for the result object. |
2 | field(Required) This is an integer value that indicates the field number to which you need to move the field search in the given result object. |
The PHP mysqli_field_seek() function returns a boolean value, and returnsTRUE, and returns if it failsFALSE.
This function was originally written in PHP version5中引入的,并且可以在所有更高版本中使用。
introduced and can be used in all higher versions.The following example demonstratesmysqli_field_seek()3Function usage (procedural style), set the result set to the position of the
<?php An example of a field pointer to a field (column) in the result set, then using mysqli_fetch_field() to get field information and output the field name, table, and maximum length: $con = mysqli_connect("localhost", "root", "password", "mydb");255mysqli_query($con, "CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR( print("Create table..... "); , 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')");1))"); , 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')");2, 'Sikhar', 'Dhawan', 'Delhi', 'India')"); , 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')");3mysqli_query($con, "INSERT INTO myplayers values( , 'Kumara', 'Sangakkara', 'Matale', 'Srilanka')"); //Retrieve the content of the table $res = mysqli_query($con, "SELECT * FROM myplayers"); //Move seek to the third field mysqli_field_seek($res, 2); //Get Field $info = mysqli_fetch_field($res); //Current Field $currentfield = mysqli_field_tell($res); print("Current Field: " . $currentfield . "\n"); print("Name: " . $info->name. "); print("Table: " . $info->table."\n"); print("Max Length: " . $info->max_length."\n"); print("Flags: " . $info->flags."\n"); print("Type: " . $info->type."\n"); //End statement mysqli_free_result($res); //Close connection mysqli_close($con); ?>
Output result
Create table..... Insert record..... Current Field: 3 Name: Last_Name Table: myplayers Max Length: 10 Flags: 0 Type: 253
In the object-oriented style, the syntax of this function is$result->field_seek;The following is an example of this function in an object-oriented style;
<?php //Establish connection $con = new mysqli("localhost", "root", "password", "mydb"); $con -> query("CREATE TABLE Test(Name VARCHAR(255), AGE INT) $con -> query("insert into Test values('Raju', 25),('Rahman', 30),('Sarmista', 27); print("Create table..... "); $stmt = $con -> prepare("SELECT * FROM Test WHERE Name in(?, ?) $stmt -> bind_param("ss", $name1, $name2); $name1 = 'Raju'; $name2 = 'Rahman'; //Execute statement $stmt->execute(); //Retrieve result $result = $stmt->get_result(); //Move the search to the second field $result->field_seek(1); //Get the second field current field $info = $result->fetch_field(); $field = $result->current_field; print("Current Field: "); print("Field Name: ");->name. "); print("Field Type: ");->type); //End statement $stmt->close(); //Close connection $con->close(); ?>
Output result
Create table..... Current Field: 2 Field Name: AGE Field Type: 3