When using php to connect to hive, use php to connect to hive. condition 1 & nbsp; thrift & nbsp must be installed; install the dependency Library yuminstallautomakelibtoolflexbisonpkgconfiggcc-c ++ boost-devellibevent-develzlib-develpython-develruby-d using php to connect to hive
Conditions for using php to connect to hive
1. install thrift
Install dependency Library
yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel
# ./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.
netstat -tnlp|grep :10000
Note: The php version is 5.2 or later.
Php connection hive code
Open (); // run queries, metadata calletc $ client-> execute ('add jar/usr/local/hadoop/hive/lib/hive-contrib-0.7.0-cdh3u0.jar '); $ client-> execute ('SELECT count (1) from apilog'); var_dump ($ client-> fetchAll (); $ transport-> close ();?>
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 connects to the hive lib package: see the attachment.
Open the browser and browse http: // localhost/test. php to view the query results.