Skip to Content
Author's profile photo Former Member

Connecting to your hana database from php using odbc.

I had spent quite some time to make a connection to my hana database from my PHP page. I did find a lot of help from the forum. I just want to take the time to help out anyone new to SAP HANA like myself. The first thing one needs to know is that the PHP’s 32 bit usually, so you’ll need to install a 32 bit hana client(to get 32bit hana odbc drivers) to make odbc connections from your PHP page. Here’s a howto : . You can check if the installation went all right by opening ODBC Data Sources (32 bit) by searching “ODBC Data Sources”, it is usually located in “C:\Windows\SysWOW64\odbcad32.exe”. If the driver HDBODBC32 is not listed in the drivers tab, you’ll have to add a new data source from the System DSN tab. Once you have the HDBODBC32(32 bit drivers) you are all set. Also note that the php odbc is set by default, so you probably won’t have to modify your php.ini. Im using xampp and did not have to do anything.

Here’s some working sample code.


$driver  = “HDBODBC32”; // 32 bit odbc drivers that come with the hana client installation.

$servername  = “”; // Enter your external access server name

$db_name = “HDB”;        // This is the default name of your hana instance.
$username = “SYSTEM”; // This is the default username, do provide your username
$password = “manager”;  // This is the default password, do provide your own password.
$conn    = odbc_connect(“Driver=$driver;ServerNode=$servername;Database=$db_name;”, $username, $password, SQL_CUR_USE_ODBC);

// example query string.

$queryString = ‘INSERT INTO “SCHEMA_NAME”.”table_name” (SiteID,Date_Time,SensorValue,KVA,PF,ErrorLog) VALUES(‘.$siteID.’,\”.$time.’\’,’.$sensorValue.’,’.$kva.’,’.$pf.’,\”.$errorLog.’\’ )’;

//echo $queryString; to get clarification, you can copy and paste your query string in SAP HANA Studio and see the results.

// if condition’s optional.

if ($conn)


     odbc_exec($conn, $queryString); // odbc_exec prepares and executes the sql statement.



Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Ivan Piñar del Prado
      Ivan Piñar del Prado

      We have problems with charset. Text is correct in PHP but is writted wrong (with rare characters) in HANA table.

      Author's profile photo sohan kanamarlapudi
      sohan kanamarlapudi

      Hello Friend,

      Even I am trying on the same solution trying to connect a PHP code. And which web server you are using to connect SAP HANA client.