PHP mysqli_field_tell() Function

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

ParameterIs RequiredDescription
resultRequired.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   w  w w .  ja  v  a 2 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/*ww w.  jav a 2 s.  c  o m*/
$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();
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions