Skip to Content
0
Mar 19 at 05:03 PM

odbc_fetch_array() will not fetch a row containing a UTF-8 currency code symbol

271 Views

I have a table in a SAP HANA database which contains currency codes and their symbols, but when I try to read them in my PHP program via ODBC the rows containing symbols are not returned in the result set.

Test script:
---------------
CREATE TABLE currency (
currency_code nvarchar(16) NOT NULL,
currency_name nvarchar(255) NOT NULL,
currency_symbol nvarchar(4) DEFAULT NULL,
PRIMARY KEY (currency_code)
);

INSERT INTO currency (currency_code, currency_name, currency_symbol) VALUES ('AUD', 'Australian Dollars', NULL);
INSERT INTO currency (currency_code, currency_name, currency_symbol) VALUES ('CAD', 'Canadian Dollars', NULL);
INSERT INTO currency (currency_code, currency_name, currency_symbol) VALUES ('EUR', 'Euros', '€');
INSERT INTO currency (currency_code, currency_name, currency_symbol) VALUES ('GBP', 'UK Pounds', '£');
INSERT INTO currency (currency_code, currency_name, currency_symbol) VALUES ('JPY', 'Japanese Yen', '¥');
INSERT INTO currency (currency_code, currency_name, currency_symbol) VALUES ('SGD', 'Singapore Dollar', '$');
INSERT INTO currency (currency_code, currency_name, currency_symbol) VALUES ('THB', 'Thai Baht', '฿');
INSERT INTO currency (currency_code, currency_name, currency_symbol) VALUES ('USD', 'US Dollars', '$');
INSERT INTO currency (currency_code, currency_name, currency_symbol) VALUES ('YUAN', 'Chinese Yuan Renminbi', '元');

<?php
$driver = 'HDBODBC';
$server = 'hxehost:39015';
$user = '****';
$pswd = '****';
$conn = odbc_connect("Driver=$driver;ServerNode=$server",$user,$pswd) OR die('Connection to DB via ODBC failed');
$query = "SELECT * FROM test.currency ORDER BY currency_code";
!$result = odbc_exec($conn, $query) OR die("ERRORNO=".odbc_error().", ERRORMSG=".odbc_errormsg());
$numrows = odbc_num_rows($result);
while ($row = odbc_fetch_array($result)) {
$array[] = array_change_key_case($row, CASE_LOWER);
echo "<p>id={$row['CURRENCY_CODE']}, name={$row['CURRENCY_NAME']}, symbol={$row['CURRENCY_SYMBOL']}</p>\n";
} // while
odbc_free_result($result);
?>

Expected result:
----------------
The call to odbc_num_rows() returns '9' which is correct, but the call to odbc_fetch_array() only returns the first 2 rows and returns FALSE for the 3rd row.