Search code examples
c#phpodbchana

PHP ODBC to HANA returns less results than expected


I have written a HANA SQL query in HANA Studio. Everything is fine, it returns all results I expected - about 43k.

Then I have written an ODBC connection in PHP, which will connect to HANA. Everything works fine until then.

Now I am executing the SAME query from HANA in my script and get much less results than I expected, sometimes 3, sometimes 148 or 1.3k results.

What is the problem: The problem could be, that there is too much data in the query. It is really a big flat table I need to read (81 columns, was not made by me, I have no choice then). So, if I am selecting less columns, I'll receive more results. Let's say I just select the ItemCode/SKU from the product, then I receive All 43k products, which is OK. Now I am adding a second column, lets say "name" which is mostly longer than the SKU of a product. Now I'm receiving just 13k items. When I'm adding a third column "description" I just receive 1.3k results. I think the size of the result is the problem.

Other funny fact: I have written earlier a tool in C#, which also uses the SAME ODBC connection to HANA. When I am using the same query like in my PHP script, I am also getting, like in HANA, ALL results.

I am working on a Windows machine, so I thought "OK, maybe XAMPP is the problem". So I tried the same thing on my own second machine, installed with Linux mint (GUI) and also on a server here at work with Ubuntu 16. I always get the same results, when I am using PHP.

So I think the problem can't be the connection to HANA (it can't, because it's working fine in the C# tool). Also it is not the query, because I'm getting all results I expected in HANA and the C# Tool. Also it is not an OS problem, it was tested on 3 different systems and always different PHP versions (also 5 and 7 was tested separately).

I also checked some ODBC settings in PHP. Maybe I have forgotten something?

There is - currently - also no alternative to switch to c#. Background: We want to read the products from SAP and want to import them into a new PIM system. A few properties will remain in SAP, so it is not just the initial import, but also a comparison later between 2-3 properties from SAP, which we then everytime need to import in the PIM software. And NO, we can NOT also move these fields to the PIM software later - it is not wanted.

I was searching the problem all the day yesterday, but I could not find anyone else with this problem. I hope someone can help me.

Does anyone also had this problems with php? I really hope someone can help me.


Solution

  • In order to avoid the problem of interrupted result set transfer, the parameter CHAR_AS_UTF8=true has to be set in the ODBC-DSN.

    See also Why does sqlQuery from SAP HANA using RODBC return no data if request 18 or more rows.