How To Connect PHP With SAP Hana

Hi Guys, welcome back to Codingofcents. Today we will learn how to connect PHP to SAP Hana database because it’s interesting if we can connect our web application with a database that developed by SAP.

SAP HANA is an in-memory, column-oriented, relational database management system developed and marketed by SAP SE. Its primary function as a database server is to store and retrieve data as requested by the applications

Before we continue, make sure you had install SAP Hana Client or you can download from SAP website. Make sure you have an account for login too ✌ ✌ ✌ . So bellow is the example connection and how we select data from database.

$driver = "HDBODBC";
$servername  = "SOMESERVER:30015";
$db_name = "DBNAME";
$username = "USERNAME";
$password = "PASSWORD";
try {
    $conn = new PDO("odbc:Driver=$driver;ServerNode=$servername; 
    $stm = $conn->query("SELECT * FROM \"DBNAME\".\"OITM\"  LIMIT 10 ");
    $arr = [];
    while ($row = $stm->fetch(PDO::FETCH_ASSOC)){
        $arr[] = [
            "ItemCode" => $row['ItemCode'],
            "ItemName" => $row['ItemName'],
            "FrgnName" => $row['FrgnName'],
    echo json_encode($arr);
} catch (Exception $e) {
    echo json_encode($e->getMessage());

As you can see we add CHAR_AS_UTF8=true at the end of connection and it will solve issue that no data fetch when run query. And here the result

Connect PHP with SAP Hana
Connect PHP with SAP Hana


Therefore, We can use any programming language to connect to SAP Hana Database that supports driver provided by Hana client installation process done.

Sponsored Links
Default image
I Wayan Tisna Adimuliarta
Hi, my name is I Wayan Tisna Adi Muliarta. You can call me Tisna. I am the author of the Coding Of Cents

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply

5 × one =