moechofe edited this page May 9, 2012 · 10 revisions
Clone this wiki locally

« Provided for easy and powerful programming related to database and web. »

This PHP tool is used to manipulate the records of a Kyoto Tycoon server. It require a PHP5.3 version or more. Here is a list of cons and pros:

  • Two ways to work with: close to the protocol and easy to use from PHP.
  • Support iterators and array access to browse the records.
  • Partial support of Rest protocol and no binary protocol yet.
  • Lot of commands's still not implemented. TODO: list it


Copy the script lib.kyoyo.php somewhere and include it in your application:

require_once 'lib.kyoyo.php';

Add an alias for the namespace \qad\kyoto or remove the namespace declaration:

use qad\kyoto;

Instanciate the class kyoto\UI with the function kyoto\UI():

$kt = kyoto\UI();

Parameters list is described in the documentation of the kyoto\UI() function.

Accessing records

The UI object supports 3 ways to set and get records.

  • Using the object like an Array:

    $kt['France'] = 'Paris';
    var_dump( $kt['France'] );
  • Using the set() and get() methods:

    $kt->set('日本', '東京');
    var_dump( $kt->get('日本') );
  • Using the magic methods:

    var_dump( $kt->Japan );

Read the documentation about the UI class to learn all the available ways to access records.

Browsing records

There is many ways to browse records: keys and values, keys only, forward, backward, matching keys by prefix or by a regular expression.

  • All records:

    foreach( $kt->forward() as $key => $value )
    var_dump( $key, $value );
  • All records in the reverse order:

    foreach( $kt->backward() as $key => $value )
    var_dump( $key, $value );
  • All records that begin with a prefix:

    foreach( $kt->begin('prefix_') as $key => $value )
    var_dump( $key, $value );
  • All records that match a regular expression:

    foreach( $kt->regex('.*_match_.*') as $key => $value )
    var_dump( $key, $value );

Read the documentation about the UI class to learn all the available ways to browse records.


The configuration may alter the behavior of the code. Change it carefully.

  • Unexisting records return null:

    By default an exception was thrown when trying to access or delete an unexisting records. Use outofbound_return_null to change this behavior. If you do need to change permanently, clone the object before.

    var_dump( $kt['unexists'] ); // display NULL
    unset($kt['unexists']); // do not throw exception
  • Connection error return false:

    The connection was not establish until a command needs to be send on the server. Thats mean probably when the first records of the session was accessed. When the connection could'nt be established, an exception was throw by default. Use runtime_return_false to change this behavior.

    $kt = new kyoto\UI('http://not.a.server');
    var_dump( $kt['exist'] ); // display FALSE