php读写操作hbase数据库的基本方法
2013-11-28 17:57
651 查看
php读写操作hbase数据库的基本方法
<?php $GLOBALS['THRIFT_ROOT'] = 'thrift'; require_once( $GLOBALS['THRIFT_ROOT'].'/Thrift.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php' ); require_once( $GLOBALS['THRIFT_ROOT'].'/packages/Hbase/Hbase.php' ); $socket = new TSocket( 'localhost', 9090 ); $socket->setSendTimeout( 10000 ); // Ten seconds (too long for production, but this is just a demo ;) $socket->setRecvTimeout( 20000 ); // Twenty seconds $transport = new TBufferedTransport( $socket ); $protocol = new TBinaryProtocol( $transport ); $client = new HbaseClient( $protocol ); $transport->open(); echo "start ...\r\n"; echo "check table exist\r\n"; $t = 'test_table'; $table = $client->getTableNames(); print_r($table); /** foreach ($table as $value){ if($value == $t){ echo "find $t,delete it\r\n"; if($client->isTableEnabled($value)){ echo "disabling $t\r\n"; $client->disableTable($value); } echo "deleting $t\r\n"; $client->deleteTable($value); } } echo "Create new table $t\r\n"; $aritcle = new ColumnDescriptor(array('name'=>'aritcle:')); $author = new ColumnDescriptor(array('name'=>'author:')); $columns = array($aritcle,$author); echo "Creating table $t\r\n"; try { $client->createTable($t,$columns); } catch (AlreadyExists $ae){ echo "$ae\r\n"; } **/ echo "Start insert some records\r\n"; $record1 = array(new Mutation(array('column'=>'aritcle:title','value'=>'hello,world!'))); $record2 = array(new Mutation(array('column'=>'aritcle:content','value'=>'welcome to hbase'))); $client->mutateRow($t,'1',$record1); $client->mutateRow($t,'1',$record2); /** echo "In sert 1000 records\r\n"; $time_start = microtime_float(); for ($i=0;$i<10000;$i++){ $record = array(new Mutation(array('column'=>'aritcle:title','value'=>$i))); $client->mutateRow($t,$i,$record); } $time_end = microtime_float(); $time = $time_end - $time_start; echo "Did nothing in $time seconds\n"; echo "rand read row \r\n"; **/ $row = $client->getRow($t,rand(1,10000)); print_r($row); $row = $client->getRowWithColumns($t,1,'aritcle:'); print_r($row); $transport->close(); function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } ?>
相关文章推荐
- noSql-Hbase-php读写操作hbase数据库的基本方法
- PHP学习笔记 1.数据库的基本操作
- php连接与操作PostgreSQL数据库的方法
- 数据库开发基本操作-安装Sql Server 2005出现“性能监视器计数器要求”错误解决方法
- 关于php PDO操作数据库的方法
- PHP学习笔记之三:数据库基本操作
- PHP入门教程之使用Mysqli操作数据库的方法(连接,查询,事务回滚等)
- 数据库开发基本操作-SQL Server 2005 不允许远程连接解决方法
- PHP读写文件的基本操作
- php 用封装类的方法操作数据库和批量删除
- C#操作本地文件及保存文件到数据库的基本方法总结
- django-10-数据库使用04 后台安装配置及增加用户对数据库基本读写操作
- PHP实现对文本数据库的数据显示、加入、修改、删除、查询五大基本操作的方法
- PHP--数据库基本操作
- php操作xml并将其插入数据库的实现方法
- PHP文件读写操作之文件读取方法详解
- 数据库操作基本方法实现
- PHP Yii 框架的数据库操作笔记 一、查询集合的方法
- Android开发笔记(十四)数据库操作的基本方法
- 数据库操作基本方法实现