Documentation

DataTable
in package
implements Countable, ArrayAccess, IteratorAggregate

Represents a data table providing functionalities like counting, array access, and iteration.

This class implements Countable, ArrayAccess, and \IteratorAggregate interfaces to provide various data manipulation capabilities.

Table of Contents

Interfaces

Countable
ArrayAccess
IteratorAggregate

Properties

$_cache  : ArrayList
List of loaded rows
$_point  : DataAccessPoint
Data access point
$_reader  : IDataReader
DataReader
$_returnAs  : string
Rows class name

Methods

__construct()  : mixed
Constructor
Affected()  : int|null
Gets the number of affected rows by the last database operation.
CacheAll()  : mixed
Caches all data from the data source.
Clear()  : void
Clears the data table, removing all elements.
Count()  : int
Gets the number of rows in the DataTable.
Create()  : DataTable
Static constructor
CreateEmptyRow()  : mixed
Creates an empty row object with optional initial data.
DeleteAllRows()  : void
Deletes all rows from the data source.
DeleteRow()  : QueryInfo
Deletes a DataRow from the data source.
Fields()  : array<string|int, mixed>
Retrieves the field names of the DataTable.
First()  : mixed
Retrieves the first item from the data table.
getIterator()  : DataTableIterator
Returns iterator
HasRows()  : bool
Checks if the DataTable has any rows.
Item()  : mixed
Retrieves an item from the data source at the specified index.
Load()  : self
Executes a query to load data into the DataTable.
offsetExists()  : bool
Checks if data exists at the specified index.
offsetGet()  : DataRow
Retrieves the value at the specified index.
offsetSet()  : void
Sets a value by index.
offsetUnset()  : void
Removes data at the specified index.
Point()  : DataAccessPoint|null
Retrieves the data access point associated with the DataTable.
SaveAllRows()  : void
Saves all DataRow objects in the data table to the data source.
SaveRow()  : QueryInfo|bool
Saves a DataRow to the data source.
Set()  : void
Sets an data at the specified index in the data table cache.
ToArray()  : array<string|int, mixed>
Converts the data table to an array.
Unpluck()  : array<string|int, mixed>
Unplucks a selected fields from table and returns array containing unplucked rows
_createDataRowObject()  : mixed
Creates a DataRow object based on the given result.
_read()  : mixed
Reads data from a data source.
_readTo()  : mixed
Reads data from a data source up to a specified index.
_getTableEncoding()  : object
Retrieves the encoding information for a specified table.

Properties

$_returnAs

Rows class name

protected string $_returnAs = null

Methods

Affected()

Gets the number of affected rows by the last database operation.

public Affected() : int|null
Return values
int|null

The number of affected rows, or null if not available.

CacheAll()

Caches all data from the data source.

public CacheAll([bool $closeReader = true ]) : mixed
Parameters
$closeReader : bool = true

(optional) Whether to close the reader after caching. Default is true.

Return values
mixed

The cached data, or null if caching fails.

Clear()

Clears the data table, removing all elements.

public Clear() : void

Count()

Gets the number of rows in the DataTable.

public Count() : int
Return values
int

The number of rows in the DataTable.

CreateEmptyRow()

Creates an empty row object with optional initial data.

public CreateEmptyRow([object|array<string|int, mixed> $data = [] ]) : mixed
Parameters
$data : object|array<string|int, mixed> = []

(optional) Initial data to populate the row object. Default is an empty array.

Return values
mixed

The created empty row object, or null if creation fails.

DeleteAllRows()

Deletes all rows from the data source.

public DeleteAllRows() : void

DeleteRow()

Deletes a DataRow from the data source.

public DeleteRow(DataRow $row) : QueryInfo
Parameters
$row : DataRow

The DataRow object to be deleted.

Return values
QueryInfo

A QueryInfo object containing information about the executed delete query.

Fields()

Retrieves the field names of the DataTable.

public Fields() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array containing the field names of the DataTable.

First()

Retrieves the first item from the data table.

public First() : mixed
Return values
mixed

The first item from the data table, or null if the collection is empty.

HasRows()

Checks if the DataTable has any rows.

public HasRows() : bool
Return values
bool

True if the DataTable has rows, false otherwise.

Item()

Retrieves an item from the data source at the specified index.

public Item(int $index) : mixed
Parameters
$index : int

The index of the item to retrieve.

Return values
mixed

The item at the specified index, or null if the index is out of range.

Load()

Executes a query to load data into the DataTable.

public Load(string $query[, array<string|int, mixed> $params = [] ]) : self
Parameters
$query : string

The SQL query to execute.

$params : array<string|int, mixed> = []

(optional) An associative array of parameters to bind to the query. Default is an empty array.

Return values
self

offsetExists()

Checks if data exists at the specified index.

public offsetExists(int $offset) : bool
Parameters
$offset : int

The index to check for data.

Return values
bool

True if data exists at the index, false otherwise.

offsetGet()

Retrieves the value at the specified index.

public offsetGet(int $offset) : DataRow
Parameters
$offset : int

The index of the value to retrieve.

Return values
DataRow

The value at the specified index.

offsetSet()

Sets a value by index.

public offsetSet(int $offset, DataRow $value) : void
Parameters
$offset : int

The index to set the value.

$value : DataRow

The value to set.

offsetUnset()

Removes data at the specified index.

public offsetUnset(int $offset) : void
Parameters
$offset : int

The index of the data to remove.

Point()

Retrieves the data access point associated with the DataTable.

public Point() : DataAccessPoint|null
Return values
DataAccessPoint|null

The data access point associated with the DataTable, or null if not set.

SaveAllRows()

Saves all DataRow objects in the data table to the data source.

public SaveAllRows() : void

SaveRow()

Saves a DataRow to the data source.

public SaveRow(DataRow $row[, string|null $idField = null ][, bool|null $convert = true ]) : QueryInfo|bool
Parameters
$row : DataRow

The DataRow object to be saved.

$idField : string|null = null

(optional) The name of the field representing the primary key. Default is null.

$convert : bool|null = true

(optional) Whether to convert data before saving. Default is true.

Return values
QueryInfo|bool

A QueryInfo object containing information about the executed query, or boolean true if successful, false otherwise.

Set()

Sets an data at the specified index in the data table cache.

public Set(int $index, ExtendedObject $data) : void
Parameters
$index : int

The index at which to set the data.

$data : ExtendedObject

The data to set.

ToArray()

Converts the data table to an array.

public ToArray([bool $noPrefix = false ]) : array<string|int, mixed>
Parameters
$noPrefix : bool = false

(optional) Whether to exclude the prefix from keys. Default is false.

Return values
array<string|int, mixed>

An array representation of the collection.

Unpluck()

Unplucks a selected fields from table and returns array containing unplucked rows

public Unpluck(array<string|int, mixed> $fields) : array<string|int, mixed>
Parameters
$fields : array<string|int, mixed>

fields to unpluck from row

Return values
array<string|int, mixed>

An array representation of the collection.

_createDataRowObject()

Creates a DataRow object based on the given result.

protected _createDataRowObject(mixed $result) : mixed
Parameters
$result : mixed

The result data to create a DataRow object from.

Return values
mixed

A DataRow object created from the given result, or null if creation fails.

_read()

Reads data from a data source.

protected _read() : mixed
Return values
mixed

The data read from the data source, or null if reading fails.

_readTo()

Reads data from a data source up to a specified index.

protected _readTo(int $index) : mixed
Parameters
$index : int

The index up to which data should be read.

Return values
mixed

The data read from the data source up to the specified index, or null if reading fails.

_getTableEncoding()

Retrieves the encoding information for a specified table.

private _getTableEncoding(string $table) : object
Parameters
$table : string

The name of the table to retrieve encoding information for.

Return values
object

An object containing encoding information for the specified table.


        
On this page

Search results