PHP Tyrant

Sign in or create your account | Project List | Help

RDBTable

How to use the RDBTable API

RDBTable works like standard database tables except you are not limited by a schema. A key can hold multiple columns, it is up to you to choose which columns are useful for your application.

Storing records

To store a new record, you decide what is your primary key and what are your data :


$tt = Tyrant::connect();
$key = 'user:1';
$cols = array('name' => 'john', 'age' => 20);
$tt->put($key, $cols);

Since the RDBTable API implements ArrayAccess, you can also store a record like this:


$tt['user:1'] = array('name' => 'john', 'age' => 20);

The RDBTable API also provides putkeep(). If a record with the same key exists in the database, this method has no effect.

There is also a putcat() to concatenate columns of the existing record. If there is no corresponding record, a new record is created.

Getting records

To get the record you either use get() or the ArrayAccess API.


$user = $tt['user:1'];
$user = $tt->get('user:1');

Searching in the database is performed using a TyrantQuery object.

Created: 8 months 25 days ago
by Bertrand Mansion

Updated: 7 months 26 days ago
by Bertrand Mansion

Labels:
Phase:Implementation

Old Revisions