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 : http://www.youtube.com/watch?v=au7eziBLAtU . 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 = “yourservername.vm.cld.sr:30015”; // 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.
odbc_exec($conn, $queryString); // odbc_exec prepares and executes the sql statement.