PHP mysqli_field_tell() Function
In this chapter you will learn:
- Definition for PHP mysqli_field_tell() Function
- Syntax for PHP mysqli_field_tell() Function
- Parameter for PHP mysqli_field_tell() Function
- Return for PHP mysqli_field_tell() Function
- Example - Get field info for all fields, then get the current field with mysqli_field_tell()
- Example - Object oriented style
Definition
The mysqli_field_tell() function returns the position of the field cursor.
Syntax
PHP mysqli_field_tell() Function has the following syntax.
mysqli_field_tell(result);
Parameter
Parameter | Is Required | Description |
---|---|---|
result | Required. | Result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result() |
Return
Returns current offset of field cursor.
Example
The follwing code gets field info for all fields, then get the current field with mysqli_field_tell() and print each column's name, table, and max length.
<?php/*from j ava2 s . c o m*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT name FROM emp";
if ($result=mysqli_query($con,$sql)){
// Get field info for all fields
while ($fieldinfo=mysqli_fetch_field($result)){
// Get field cursor position
$currentfield=mysqli_field_tell($result);
printf("Column %d:\n", $currentfield);
printf("Name: %s\n", $fieldinfo->name);
printf("Table: %s\n", $fieldinfo->table);
}
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
Example 2
<?php/* j av a 2 s . c om*/
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT name, salary from emp";
if ($result = $mysqli->query($query)) {
// Get field information for all columns
while ($finfo = $result->fetch_field()) {
// get fieldpointer offset
$currentfield = $result->current_field;
printf("Column %d:\n", $currentfield);
printf("Name: %s\n", $finfo->name);
printf("Table: %s\n", $finfo->table);
printf("max. Len: %d\n", $finfo->max_length);
printf("Flags: %d\n", $finfo->flags);
printf("Type: %d\n\n", $finfo->type);
}
$result->close();
}
$mysqli->close();
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_free_result() Function
- Syntax for PHP mysqli_free_result() Function
- Parameter for PHP mysqli_free_result() Function
- Example - retrieves rows from a resultset, then free the memory associated with the resultset
Home » PHP Tutorial » PHP MySQLi Functions