Bug #80874 [Fbk->Asn]: odbc_fetch_array() will not fetch a row containing a UTF-8 currency code symbol

From: Date: Thu, 18 Mar 2021 15:28:27 +0000
Subject: Bug #80874 [Fbk->Asn]: odbc_fetch_array() will not fetch a row containing a UTF-8 currency code symbol
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232850@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80874&edit=1 ID: 80874 User updated by: tony at tonymarston dot net Reported by: tony at tonymarston dot net Summary: odbc_fetch_array() will not fetch a row containing a UTF-8 currency code symbol -Status: Feedback +Status: Assigned Type: Bug Package: ODBC related Operating System: Windows 10 PHP Version: 7.4.16 Assigned To: cmb Block user comment: N Private report: N New Comment: No notice or warning is generated on the call to odbc_fetch_array(). I have CHAR_AS_UTF8=TRUE in the additional connection properties in the ODBC Data Source Administrator. When I access my SQL Server database via ODBC the currency symbol returned for THB appears as '?' in the PHP array and also when I display it in the HTML output. However, when I copy it to my text editor it is shown as '?' in ASCII and 'EFBBBF3F' in hexadecimal. Why does it show up as '?' Previous Comments: ------------------------------------------------------------------------ [2021-03-18 13:03:49] cmb@php.net >> Doesn't it also raise a warning? > How do I detect that? There is no ODBC function to retrieve > warnings. I was referring to the general PHP error reporting mechanisms. Anyway, the ODBC trace shows whats going on: | General error;-10427 Conversion of parameter/column (3) from | data type NVARCHAR to ASCII failed (-10427) Conversion to ASCII can't succeed, but PHP does not enforce that, but rather requests binding to SQL_C_CHAR. Is there a respective setting to convert to UTF-8 in the driver options? With SQL Server (ODBC Driver 17 for SQL Server) all currency symbols are properly retrieved and displayed for me. Watch out for font issues (call bin2hex() to see the byte values). ------------------------------------------------------------------------ [2021-03-17 18:27:28] tony at tonymarston dot net > Doesn't it also raise a warning? How do I detect that? There is no ODBC function to retrieve warnings. The trace log can be downloaded from http://www.tonymarston.net/odbc.log I have also tried running the same test on my SQL Server database, but while it does return all 9 rows the currency_symbol column for 'THB' and 'YUAN' are being returned as '?' instead of the expected UTF-8 symbol. ------------------------------------------------------------------------ [2021-03-17 16:02:18] cmb@php.net > […] but the call to odbc_fetch_array() only returns the first 2 > rows and returns FALSE for the 3rd row. Doesn't it also raise a warning? Anyhow, I cannot reproduce this (I haven't a SAP HANA DB available, though), so please provide an ODBC trace so we can see what's actually happening. If possible, put it somewhere on the Web (e.g. gist.github.com, pastebin.com) and only post a link to the trace here. ------------------------------------------------------------------------ [2021-03-16 18:11:38] tony at tonymarston dot net Description: ------------ I have a database table in a SAP HANA database which contains currency codes and their symbols, but when I try to read them in my PHP program 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"; if (!$result = odbc_exec($conn, $query)) { 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80874&edit=1

« previous php.bugs (#232850) next »