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.
[email protected]: 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.
[email protected]: apt-get install php7.0-odbc
You will need to restart apache, once restarted, execute the following commands again.
[email protected]: 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.
$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.
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.
[email protected]: isql --version
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 - 2657 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 - 2758 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 - 4127 views
Adding Auto Numbers To Table Columns
This article explains how to create an auto generated column using IDENTITY.14 March 2018 - 1647 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 - 2650 views
Loading And Unloading Column Table Into And From Memory
This article explains how to load and unload a column table into and from memory.18 October 2017 - 1710 views
M_SERVICE_MEMORY System View
This article explains how to view detailed information on memory for HANA services.01 August 2017 - 2380 views