class mysqli_result implements IteratorAggregate (View source)

Represents the result set obtained from a query against the database.

Implements Traversable since 5.4

Properties

int $current_field
int $field_count
array|null $lengths
int $num_rows
mixed $type

Methods

__construct(mysqli $mysql, int $result_mode = MYSQLI_STORE_RESULT)

Constructor (no docs available)

void
close()

Frees the memory associated with a result

void
free()

Frees the memory associated with a result

bool
data_seek(int $offset)

Adjusts the result pointer to an arbitrary row in the result

object|false
fetch_field()

Returns the next field in the result set

array
fetch_fields()

Returns an array of objects representing the fields in a result set

object|false
fetch_field_direct(int $index)

Fetch meta-data for a single field

array
fetch_all(int $mode = MYSQLI_NUM)

Fetches all result rows as an associative array, a numeric array, or both

array|false|null
fetch_array(int $mode = MYSQLI_BOTH)

Fetch the next row of a result set as an associative, a numeric array, or both

array|false|null
fetch_assoc()

Fetch the next row of a result set as an associative array

object|false|null
fetch_object(T> $class = 'stdClass', array $constructor_args = [])

No description

array|false|null
fetch_row()

Fetch the next row of a result set as an enumerated array

string|int|float|false|null
fetch_column(int $column = 0)

Fetch a single column from the next row of a result set

field_seek(int $index)

Set result pointer to a specified field offset

void
free_result()

Frees the memory associated with a result

getIterator()

No description

Details

__construct(mysqli $mysql, int $result_mode = MYSQLI_STORE_RESULT)

Constructor (no docs available)

Parameters

mysqli $mysql
int $result_mode [optional]

void close()

Frees the memory associated with a result

Return Value

void

void free()

Frees the memory associated with a result

Return Value

void

bool data_seek(int $offset)

Adjusts the result pointer to an arbitrary row in the result

Parameters

int $offset

The field offset. Must be between zero and the total number of rows minus one (0..mysqli_num_rows - 1).

Return Value

bool

true on success or false on failure.

object|false fetch_field()

Returns the next field in the result set

Return Value

object|false

an object which contains field definition information or false if no field information is available.

Object properties
Property Description
name The name of the column
orgname Original column name if an alias was specified
table The name of the table this field belongs to (if not calculated)
orgtable Original table name if an alias was specified
def Reserved for default value, currently always ""
db Database (since PHP 5.3.6)
catalog The catalog name, always "def" (since PHP 5.3.6)
max_length The maximum width of the field for the result set.
length The width of the field, as specified in the table definition.
charsetnr The character set number for the field.
flags An integer representing the bit-flags for the field.
type The data type used for this field
decimals The number of decimals used (for integer fields)

array fetch_fields()

Returns an array of objects representing the fields in a result set

Return Value

array

an array of objects containing field definition information.

Object properties
Property Description
name The name of the column
orgname Original column name if an alias was specified
table The name of the table this field belongs to (if not calculated)
orgtable Original table name if an alias was specified
def The default value for this field, represented as a string
max_length The maximum width of the field for the result set.
length The width of the field, as specified in the table definition.
charsetnr The character set number for the field.
flags An integer representing the bit-flags for the field.
type The data type used for this field
decimals The number of decimals used (for integer fields)

object|false fetch_field_direct(int $index)

Fetch meta-data for a single field

Parameters

int $index

The field number. This value must be in the range from 0 to number of fields - 1.

Return Value

object|false

an object which contains field definition information or false if no field information for specified fieldnr is available.

Object attributes
Attribute Description
name The name of the column
orgname Original column name if an alias was specified
table The name of the table this field belongs to (if not calculated)
orgtable Original table name if an alias was specified
def The default value for this field, represented as a string
max_length The maximum width of the field for the result set.
length The width of the field, as specified in the table definition.
charsetnr The character set number for the field.
flags An integer representing the bit-flags for the field.
type The data type used for this field
decimals The number of decimals used (for integer fields)

array fetch_all(int $mode = MYSQLI_NUM)

Fetches all result rows as an associative array, a numeric array, or both

Parameters

int $mode

[optional]

This optional parameter is a constant indicating what type of array should be produced from the current row data. The possible values for this parameter are the constants MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH.

Return Value

array

an array of associative or numeric arrays holding result rows.

array|false|null fetch_array(int $mode = MYSQLI_BOTH)

Fetch the next row of a result set as an associative, a numeric array, or both

Parameters

int $mode

[optional]

This optional parameter is a constant indicating what type of array should be produced from the current row data. The possible values for this parameter are the constants MYSQLI_ASSOC, MYSQLI_NUM, or MYSQLI_BOTH.

By using the MYSQLI_ASSOC constant this function will behave identically to the mysqli_fetch_assoc, while MYSQLI_NUM will behave identically to the mysqli_fetch_row function. The final option MYSQLI_BOTH will create a single array with the attributes of both.

Return Value

array|false|null

an array representing the fetched row, null if there are no more rows in the result set, or false on failure.

array|false|null fetch_assoc()

Fetch the next row of a result set as an associative array

Return Value

array|false|null

an associative array representing the fetched row, where each key in the array represents the name of one of the result set's columns, null if there are no more rows in the result set, or false on failure.

object|false|null fetch_object(T> $class = 'stdClass', array $constructor_args = [])

No description

Parameters

T> $class

[optional]

The name of the class to instantiate, set the properties of and return. If not specified, a stdClass object is returned.

array $constructor_args

[optional]

An optional array of parameters to pass to the constructor for class_name objects.

Return Value

object|false|null

an object representing the fetched row, where each property represents the name of the result set's column, null if there are no more rows in the result set, or false on failure.

array|false|null fetch_row()

Fetch the next row of a result set as an enumerated array

Return Value

array|false|null

an enumerated array representing the fetched row, null if there are no more rows in the result set, or false on failure.

string|int|float|false|null fetch_column(int $column = 0)

Fetch a single column from the next row of a result set

Parameters

int $column

[optional]

0-indexed number of the column you wish to retrieve from the row. If no value is supplied, the first column will be returned.

Return Value

string|int|float|false|null

a single column from the next row of a result set or false if there are no more rows.

field_seek(int $index)

Set result pointer to a specified field offset

Parameters

int $index

The field number. This value must be in the range from 0 to number of fields - 1.

void free_result()

Frees the memory associated with a result

Return Value

void

Traversable getIterator()

Since: 8.0

No description

Return Value

Traversable

An instance of an object implementing Iterator or Traversable