Skip to content
Ryan Liu edited this page Jan 9, 2015 · 5 revisions

Welcome to the php-ext-handlersocketi wiki!

Enable HandlerSocket in MariaDB

See Getting Started with the MariaDB HandlerSocket Plugin

Connect

    $hs = new HandlerSocketi('127.0.0.1', 9998);
    $fields = ['id', 'username', 'age'];
    $query = $hs->open_index('dbname', 'users', $fields);

Select

  • Get by primary key
    $result = $query->find(5);
    var_dump($result);
  • Find by primary key
    $result = $query->find(['<=' => 10], ['limit' => 5, 'offset' => 2]);
    var_dump($result);
  • Get by index
    $options = ['index' => 'username'];
    $query = $hs->open_index('dbname', 'users', $fields, $options);
    $result = $query->find('ryan');
    var_dump($result);

Modify

  • Insert
    $query = $hs->open_index('dbname', 'users', $fields);
    $result = $query->insert([
        'id' => 2, 
        'username' => 'jane',
        'age' => 20,
    ]);
    var_dump($result);
  • Delete/Remove
    $options = ['index' => 'username'];
    $query = $hs->open_index('dbname', 'users', $fields, $options);
    $result = $query->remove('ryan');
    var_dump($result);
  • Update
    $options = ['index' => 'username'];
    $query = $hs->open_index('dbname', 'users', $fields, $options);
    $result = $query->update('jane', [2, 'jane', 18]);
    var_dump($result);

Multiple operations

    $options = ['index' => 'username'];
    $query = $hs->open_index('dbname', 'users', $fields, $options);
    $result = $query->multi([
        ['find', 'ryan'],
        ['find', 'jane'],
    ]);
    var_dump($result);