Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to connect PHP with HIVE through THRIFT

avatar

Hello,

I have 4 node HDPcluster .in that second node I installed Hiveserver2 and apache lamp server.

What are all the configurations should I give for thrift PHP and Hive. I want to know the prerequisites for thrift with hive and steps to connect hive and php

1 ACCEPTED SOLUTION

avatar
Super Collaborator

@Hariprasanth Madhavan You can connect via ODBC to Query HiveServer2.

ODBC Driver can be downloaded from: https://hortonworks.com/downloads/ -> HDP Addons

View solution in original post

4 REPLIES 4

avatar
Super Collaborator

@Hariprasanth Madhavan You can connect via ODBC to Query HiveServer2.

ODBC Driver can be downloaded from: https://hortonworks.com/downloads/ -> HDP Addons

avatar
@Chiran Ravani

Thank you,

Can you refer me a configuration and package details for ODBC Connectivity? give me an Example Code for the hive and PHP ODBC connectivity.

I referred this link also https://cwiki.apache.org/confluence/display/Hive/HiveODBC but, I can't able to connect with Hive Properly.

avatar
Super Collaborator

Here is the sample code which may help you.

<html>
  <body>
    <?php
      $conn=odbc_connect('TestODBC','hive','');
 if (!$conn){
    exit("Connection to the database Failed: " . $conn);
 }
 $sql="show databases";
 $resultSet=odbc_exec($conn, $sql);
 if (!$resultSet){
    exit("Error!");}
           echo "<table><tr>";
    echo "<th>Database Name</th>";
    while (odbc_fetch_row($resultSet))
      {
  $dbName=odbc_result($resultSet,"database_name");
  echo "<tr><td>$dbName</td></tr>";
    }
    odbc_close($conn);
    echo "</table>";
    ?>
 </body>
</html>

Note: I do not have any authentication metod set for Hive, so I have used AuthMEth=2 in my odbc.ini file as below.

[TestODBC]
Description=Hortonworks Hive
Driver=/usr/lib/hive/lib/native/Linux-amd64-64/libhortonworkshiveodbc64.so
Host=HiveServer2Hotname
PORT=10000
schema=default
HiveServerType=2
AuthMech=2
ThriftTransport=0

Below is Sample Output

92473-screen-shot-2018-09-18-at-25450-am.png

avatar
Super Collaborator
@Hariprasanth Madhavan

Please mark the answer, if you see it correct 🙂