Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to connect PHP with HIVE through THRIFT

Solved Go to solution
Highlighted

How to connect PHP with HIVE through THRIFT

New Contributor

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

Accepted Solutions

Re: How to connect PHP with HIVE through THRIFT

Contributor

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

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

4 REPLIES 4

Re: How to connect PHP with HIVE through THRIFT

Contributor

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

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

Re: How to connect PHP with HIVE through THRIFT

New Contributor
@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.

Re: How to connect PHP with HIVE through THRIFT

Contributor

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

Re: How to connect PHP with HIVE through THRIFT

Contributor
@Hariprasanth Madhavan

Please mark the answer, if you see it correct :)

Don't have an account?
Coming from Hortonworks? Activate your account here