PHP Function Reference

PHP mysqli_result $current_field Property



The PHP mysqli_result::$current_field / mysqli_field_tell() function returns the position of the field cursor used for the last mysqli_fetch_field() call. This value can be used as an argument to mysqli_field_seek().

Syntax

//Object-oriented style
$mysqli_result->current_field;

//Procedural style
mysqli_field_tell(result)

Parameters

result Required. For procedural style only: Specify a mysqli_result object returned by mysqli_query(), mysqli_store_result(), mysqli_use_result() or mysqli_stmt_get_result().

Return Value

Returns current offset of field cursor.

Example: Object-oriented style

The example below shows the usage of mysqli_result::$current_field property.

<?php
//establishing connection to the database
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
  echo "Failed to connect to MySQL: ". $mysqli->connect_error;
  exit();
}

//getting query result from the database
$sql = "SELECT Name, Age FROM Employee ORDER BY Age";

if ($result = $mysqli->query($sql)) {

  //getting field information for all columns
  while ($finfo = $result->fetch_field()) {

    //getting 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\n", $finfo->max_length);
  }

  //free the memory associated with the result
  $result->close();
}

//closing the connection
$mysqli->close();
?>

The output of the above code will be similar to:

Column 1:
Name:     Name
Table:    Employee
max. Len: 50

Column 2:
Name:     Age
Table:    Employee
max. Len: 10

Example: Procedural style

The example below shows the usage of mysqli_field_tell() function.

<?php
//establishing connection to the database
$mysqli = mysqli_connect("localhost", "user", "password", "database");
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: ". mysqli_connect_error();
  exit();
}

//getting query result from the database
$sql = "SELECT Name, Age FROM Employee ORDER BY Age";

if ($result = mysqli_query($mysqli, $sql)) {

  //getting field information for all columns
  while ($finfo = mysqli_fetch_field($result)) {

    //getting fieldpointer offset
    $currentfield = mysqli_field_tell($result);

    printf("Column %d:\n", $currentfield);
    printf("Name:     %s\n", $finfo->name);
    printf("Table:    %s\n", $finfo->table);
    printf("max. Len: %d\n\n", $finfo->max_length);
  }

  //free the memory associated with the result
  mysqli_free_result($result);
}

//closing the connection
mysqli_close($mysqli);
?>

The output of the above code will be similar to:

Column 1:
Name:     Name
Table:    Employee
max. Len: 50

Column 2:
Name:     Age
Table:    Employee
max. Len: 10

❮ PHP MySQLi Reference