Conditions for using PHP to connect to hive
1. Install Thrift
#./Configure -- without-Ruby
# Make & make install
If libevent-devel is not installed, install the two dependent libraries Yum-y install libevent-devel first.
Start hive thrift after installation
#./Hive -- service hiveserver>/dev/null 2>/dev/null &
Check whether the default port 10000 of hiveserver is enabled. If yes, it indicates that the port is successfully enabled.
Note: The PHP version is 5.2 or later.
PHP connection to hiveCode
<? </P> <p> // path of the hive thrift dependency package in PHP connection <br/> $ globals ['thrift _ root'] = '/var/www/html/hivephp/ thrift /'; <br/> // load the required files for connecting to hive <br/> require_once $ globals ['thrift _ root']. 'packages/hive_service/thrithive. PHP '; <br/> require_once $ globals ['thrift _ root']. 'Transport/tsocket. PHP '; <br/> require_once $ globals ['thrift _ root']. 'protocol/ tbinaryprotocol. php'; <br/> // set up the T Ransport/protocol/client <br/> $ transport = new tsocket ('localhost', 10000); <br/> $ protocol = new tbinaryprotocol ($ transport ); <br/> $ client = new thrithiveclient ($ Protocol); <br/> $ transport-> open (); </P> <p> // run queries, metadata calletc </P> <p> $ client-> execute ('add JAR/usr/local/hadoop/hive/lib/hive-contrib-0.7.0-cdh3u0.jar '); <br/> $ client-> execute ('select count (1) From apilog'); <br/> var_dump ($ Client-> fetchall (); <br/> $ transport-> close (); </P> <p >?>
Save the above Code as the WWW path/var/www/html/from test. php to Apache and put the dependency package of PHP to/var/www/html/hivephp/thrift/
PHP connection to hive lib package http://download.csdn.net/source/3409880
Open the browser and browse http: // localhost/test. php to view the query results.