<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $bdb = new TCBDB(TCBDB::KTINT64);
    $bdb->setcmpfunc(TCBDB::CMPINT64);
    $bdb->open('casket-i64s.bdb', TCBDB::OWRITER | TCBDB::OCREAT);
    // big number string representations
    $bdb->put('98765432102', 'hop');
    $bdb->put('98765432100', 'step');
    $bdb->put('98765432101', 'jump');
    echo $bdb->get('98765432102'), "\n";
    echo "-\n";
    foreach ($bdb as $key => $value) {
        printf("%s(%s):%s\n", gettype($key), $key, $value);
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $bdb->path(), $bdb->rnum(), $bdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
Exemple #2
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $bdb = new TCBDB(TCBDB::KTINT32);
    $bdb->setcmpfunc(TCBDB::CMPINT32);
    $bdb->open('casket-i32.bdb', TCBDB::OWRITER | TCBDB::OCREAT);
    $bdb->put(2, 'hop');
    $bdb->put(0, 'step');
    $bdb->put(1, 'jump');
    echo $bdb->get(2), "\n";
    echo "-\n";
    foreach ($bdb as $key => $value) {
        printf("%s(%s):%s\n", gettype($key), $key, $value);
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $bdb->path(), $bdb->rnum(), $bdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $bdb = new TCBDB(TCBDB::KTBINARY, TCBDB::VTSERIALIZED);
    $bdb->open('casket-s.bdb', TCBDB::OWRITER | TCBDB::OCREAT);
    $bdb->put('foo', array('hop', 'Hop', 'HOP'));
    $bdb->put('bar', array('step', 'Step'));
    $bdb->put('baz', array('jump'));
    var_dump($bdb->get('foo'));
    echo "-\n";
    foreach ($bdb as $key => $value) {
        printf("%s:%s", $key, print_r($value, true));
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $bdb->path(), $bdb->rnum(), $bdb->fsiz());
    $bdb->sync();
    unset($bdb);
    // destruct
    echo "--\n";
    $raw = new TCBDB();
    $raw->open('casket-s.bdb', TCBDB::OREADER);
    foreach ($raw as $key => $value) {
        printf("%s:%s\n", $key, $value);
    }
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $bdb = new TCBDB();
    $bdb->open('casket.bdb', TCBDB::OWRITER | TCBDB::OCREAT);
    $bdb->put('foo', 'hop');
    $bdb->put('bar', 'step');
    $bdb->put('baz', 'jump');
    echo $bdb->get('foo'), "\n";
    echo "-\n";
    foreach ($bdb as $key => $value) {
        printf("%s:%s\n", $key, $value);
    }
    echo "-\n";
    $cur = new TCBDBCUR($bdb);
    $cur->jump('bar');
    vprintf("%s:%s\n", $cur->rec());
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $bdb->path(), $bdb->rnum(), $bdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}