An abstraction to retrieve data form a database.

This version of WebLab_Table provides support for PHP 5.2.6 and higher.

author Jorgen Evens
package WebLab

 Methods

Count the number of records in a table.

countAll() : int

Returns

intThe amount of records found.

Create a record for this table.

create(mixed $object) 

The id of the new record will be set in $object

Parameters

$object

mixed

The object to insert as a record.

Create an instance of a WebLab_Data_Table to be used internally.

createTable() : \WebLab_Data_Table

Returns

\WebLab_Data_TableAn instance of the abstraction layer Table class.

Delete a record from the table.

delete(mixed $object) 

If soft-delete is used it will only update the deleted and online field.

Parameters

$object

mixed

The object to delete from the table.

Find a record by its primary key.

find($key) : mixed

Parameters

$key

Returns

mixedThe record as an object.

Find all the records in the table from $start to $start+$count.

findAll(int $count, int $start, int $result_count) : mixed

Parameters

$count

int

The amount of records to retrieve.

$start

int

The offset to start retrieving from.

$result_count

int

&$result_count If different from false, will be set to the total amount of records in the table.

Returns

mixedAn array of objects representing a record.

Find records by a set of filters.

findBy(mixed $field, mixed $value, int $result_count) : mixed

Parameters

$field

mixed

The fieldname or a list of filters to use as $column => $value pairs.

$value

mixed

If field is a fieldname, the value it should match.

$result_count

int

&$result_count If different from false, will be set to the amount of records.

Returns

mixedAn array of objects representing a record.

Singleton method to retrieve an instance.

getInstance() : \WebLab_Table
Static

Returns

End the transaction on the database.

quitTransaction(boolean $commit) 
Static

Parameters

$commit

boolean

Should changes be committed or discarded.

Update a record if it already exists, insert it otherwise.

save(mixed $object) 

Parameters

$object

mixed

The object to insert as a record.

Start a transaction on the database.

startTransaction() 
Static

Retrieve the name of the table using the prefix set for this database.

table() : string
Static
see \WebLab_Database

Returns

stringThe full table name

Update a record in the table.

update(mixed $object) 

Parameters

$object

mixed

The new values for this record, including the unaltered primary key.

Detect if a field is in the column list.

_hasField($field) : boolean
Static

Parameters

$field

The name of the column to test for.

Returns

booleanTrue if field is present.

 Properties

 

$_database : string
 

$_fields : mixed
 

$_instance : \WebLab_Table
 

$_primary_keys : mixed

If there is a auto_increment field, it should be the first in this list. find( $id ) calls will be matched against the first field in this array.

 

$_table : string