mysql_field_seek Function in PHP
What is mysql_field_seek() function in PHP?
How does mysql_field_seek works?
Explanation
mysql_field_seek function points to a specified field in the resultset.
Syntaxint mysql_field_seek ( resource result, int field_offset)
Returns TRUE on success, or FALSE and a warning on search failure.
mysql_field_seek() moves the internal pointer in a result set returned by
mysql_query() function to a specific field search.
Internal Pointer is moved to specific field based on the search value of field_offset. Field offsets for the first field is '0', second is '1' and so on.
Example:
<?php // Attempt to connect to the default database server $link = mysql_connect("mysql_host", "mysql_user", "mysql_password") or die ("Could not connect"); //select database $db_select = mysql_selectdb("mydb",$link); //returns result set on executing the query $result=mysql_query("select * from user",$link); mysql_field_seek($result,3); print_r(mysql_fetch_field($result)); mysql_close($link); ?> |
In the above example
mysql_query() executes simple query and returns search result set. Result set is passed as the first arguments and field index of the result set which is to be pointed is passed as the second arguments to the mysql_field_seek function for the purpose of internal pointer to be moved to the specified field.
After the pointer is moved to the specified field , we can perform any operation on the field.
In the above code after the pointer is moved to the fourth field based on field offset 3,
mysql_fetch_field() function is executed and the field information is displayed.
RESULT:
stdClass Object (
[name] => description
[table] => user
[def] =>
[max_length] => 0
[not_null] => 0
[primary_key] => 0
[multiple_key] => 0
[unique_key] => 0
[numeric] => 0
[blob] => 1
[type] => blob
[unsigned] => 0
[zerofill] => 0
)
See also: mysql_fetch_field()