// open connection $socket = new TSocket(HBASE_HOST, HBASE_PORT); $transport = new TBufferedTransport($socket); $protocol = new TBinaryProtocol($transport); $transport->open(); // create hbase client $client = new HbaseClient($protocol); // show all tables echo "Existing tables:\n"; $tables = $client->getTableNames(); foreach ($tables as $name) { echo " found: {$name}\n"; } // create a table with name 'tableName' echo "\nCreate table: tableName\n"; try { $columns = array(new ColumnDescriptor(array('name' => 'colFamily:', 'maxVersions' => 10))); $client->createTable("tableName", $columns); } catch (AlreadyExists $ae) { echo "WARN: {$ae->message}\n"; } // insert data to table echo "\nInsert data to table: tableName\n"; $mutations = array(new Mutation(array('column' => 'colFamily:Col', 'value' => 'value123'))); $client->mutateRow("tableName", "ID_1237846634624", $mutations); // get table data echo "\nData in table: tableName\n"; $rows = $client->getRow("tableName", "ID_1237846634624"); foreach ($rows as $row) { var_dump($row); }
if ($name == $t) { if ($client->isTableEnabled($name)) { echo " disabling table: {$name}\n"; $client->disableTable($name); } echo " deleting table: {$name}\n"; $client->deleteTable($name); } } # # Create the demo table with two column families, entry: and unused: # $columns = array(new ColumnDescriptor(array('name' => 'entry:', 'maxVersions' => 10)), new ColumnDescriptor(array('name' => 'unused:'))); echo "creating table: {$t}\n"; try { $client->createTable($t, $columns); } catch (AlreadyExists $ae) { echo "WARN: {$ae->message}\n"; } echo "column families in {$t}:\n"; $descriptors = $client->getColumnDescriptors($t); asort($descriptors); foreach ($descriptors as $col) { echo " column: {$col->name}, maxVer: {$col->maxVersions}\n"; } # # Test UTF-8 handling # $invalid = "foo-������"; $valid = "foo-生ビール"; # non-utf8 is fine for data