PHP mysqli_current_field() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
MySQLi

Definition

In PHP, mysqli_current_field refers to the current field cursor on a mysqli_result: read $result->current_field in object style, or call mysqli_field_tell($result) procedurally.

The value is the offset used by the last mysqli_fetch_field() call. You need a result object from query(), store_result(), use_result() or stmt_get_result(). Pair it with field_seek() when you want to jump to a column definition.

Syntax

Call mysqli_current_field() with the values you need. Start with this line.

PHP
$offset = mysqli_field_tell($result);
CallWhat it does
$result->current_fieldObject-oriented property: current field cursor offset.
mysqli_field_tell($result)Procedural function that returns the same offset.
mysqli_field_seek($result, 0)Moves the field cursor back to the first column.

There is no separate mysqli_current_field() function name in PHP. The manual documents mysqli_result::$current_field together with mysqli_field_tell(). Both need a mysqli_result, not a connection.

Library declarations
PHP
mysqli_field_tell(mysqli_result $result): int

Parameters

ParameterDescription
resultRequired (procedural). A mysqli_result from a SELECT-style query.

Return Value

Return ValueDescription
intThe current field cursor offset (after fetch_field advances it).

PHP Examples

Example 1 — Read current_field While Fetching Metadata

Loop fetch_field and print the cursor. Sample output when connected to a demo database.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
$result = mysqli_query($mysqli, "SELECT id, name FROM products LIMIT 1");

while ($field = mysqli_fetch_field($result)) {
    echo "offset=", mysqli_field_tell($result), " name=", $field->name, PHP_EOL;
}

mysqli_free_result($result);
mysqli_close($mysqli);

How It Works

  1. A SELECT returns a mysqli_result with two columns.
  2. mysqli_fetch_field() walks column definitions.
  3. mysqli_field_tell() (procedural current_field) prints the offset after each fetch.
  4. Sample output lists id then name.

Example 2 — Object Property Form

Use $result->current_field in object-oriented style.

PHP
<?php
$mysqli = new mysqli("localhost", "demo", "secret", "shop");
$result = $mysqli->query("SELECT id, name, price FROM products LIMIT 1");

while ($field = $result->fetch_field()) {
    echo $result->current_field, ":", $field->name, PHP_EOL;
}

$result->free();
$mysqli->close();

How It Works

  1. query() returns a mysqli_result object.
  2. fetch_field() advances the field cursor.
  3. current_field reports the new offset each time.
  4. Three columns produce three sample lines.

Example 3 — Seek Then Read the Cursor

Jump to column 0 with field_seek and show the cursor before fetching.

PHP
<?php
$mysqli = mysqli_connect("localhost", "demo", "secret", "shop");
$result = mysqli_query($mysqli, "SELECT id, name FROM products LIMIT 1");

mysqli_fetch_field($result);
mysqli_field_seek($result, 0);
echo "after seek: ", mysqli_field_tell($result), PHP_EOL;

mysqli_free_result($result);
mysqli_close($mysqli);

How It Works

  1. One fetch_field() moves the cursor forward.
  2. field_seek($result, 0) resets to the first field.
  3. field_tell() reports offset 0.
  4. This pattern is useful when re-reading column metadata.

Frequently Asked Questions

It is the field-metadata cursor on a mysqli_result. OO style reads $result->current_field; procedurally you call mysqli_field_tell($result).
No. PHP documents the property mysqli_result::$current_field and the procedural function mysqli_field_tell() together.
No. You need a mysqli_result from a query that returns fields.
Use mysqli_field_seek($result, $index) or $result->field_seek($index), then read current_field / field_tell again.
data_seek moves between result rows. current_field / field_tell track column definition position for fetch_field().

Next: mysqli_data_seek()

mysqli_data_seek() moves the row cursor of a buffered mysqli_result to a given offset so t.

mysqli_data_seek() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful