Install PHP ODBC
First ensure that the ODBC driver for PHP is installed. You can do this by executing the command below in a terminal.
root@workstation: php --info | grep odbc
If the output is empty, it means the ODBC driver is not installed. You can install the driver from the terminal by executing the following command.
root@workstation: apt-get install php7.0-odbc
You will need to restart apache, once restarted, execute the following commands again.
root@workstation: php info | grep odbc
If the driver was installed successfully, you should notice entries for ODBC. Look at the PDO drivers and ensure ODBC is available.
Download HANA Client Library
The final step is to install the HANA ODBC client library. The easiest way to do this, is to download HANA Express. On the download manager screen, select Clients (Linux X86/64). Be sure to select the Binary Installer from the Image dropdown list. Once downloaded unzip and extract the folder contents. The folder should include the hdbsetup script. Execute this script, to invoke the client setup wizard. Take note of the location where the client is being installed.
After the installation is complete, extract the contents of ODBC.TGZ located in the client folder to a suitable location. The ODBC.TGZ contains the libodbcHDB.so driver.
Sample PDO Connection
With the PHP ODBC and HANA client library installed, we can now write a basic PHP script to test the connection. The quickest way to do this, is to refer to the HANA ODBC driver within the connection string.
Listing 1
$driver = "/path/to/HANA/driver/libodbcHDB.so";
$host = "";
$uid = "";
$pwd = "";
$pdo = new PDO("odbc:Driver=$driver;ServerNode=$host; Uid=$uid;Pwd=$pwd;");
$stm = $pdo->query('SELECT NOW() AS "now" FROM DUMMY');
$obj = $stm->fetch(PDO::FETCH_OBJ);
echo $obj->now;
The sample code above executes a simple SQL query that returns the current date and time as an object.
Troubleshooting
Check that you have the most recent version of unixODBC installed. The version should be at least 2.3 or higher. To check the current version, use the following command.
root@workstation: isql --version
-
JSON_TABLE Function
In this article, we'll take a look at how to use the ++JSON_TABLE++ function to represent JSON data stored in a regular column as a relational table.
31 March 2023 - 2405 views -
Connect To HANA DB Using Rust
Learn how to connect and query a HANA database using Rust with the hdbconnect package.
21 February 2023 - 2587 views -
If Table Exists Function
In this article, I explain how to create a function to determine if a table exists in SAP HANA.
31 October 2019 - 8594 views -
Connect To HANA DB Using NodeJs
This article explains how to connect to a SAP HANA system using the Node HANA client library.
28 October 2019 - 6963 views -
Connect To HANA DB Using Python
This article explains how to connect to a SAP HANA system using the Python hdbcli package.
11 October 2018 - 7730 views -
Adding Auto Numbers To Table Columns
This article explains how to create an auto generated column using IDENTITY.
14 March 2018 - 5956 views -
Connect To HANA DB Using Java
This article describes how to connect to a HANA DB system using the ngdbc.jar Java driver.
03 November 2017 - 5244 views