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:
> 'EFBBBF3F' in hexadecimal is a UTF-8 BOM followed by a question mark.
Byte Order Marks should *NEVER* be added to database columns, only files.
> Did you try with CHAR_AS_UTF8=FALSE?
Yes, but the results were the same.
> would this work with PDO_ODBC?
Accessing the SAP HANA database had the same result - it stopped fetching rows after the 2nd row.
Access the SQL Server database had a different result - the symbol for 'THB' was returned
as '?' on its own without the UTF-8 BOM.
Previous Comments:
------------------------------------------------------------------------
[2021-03-18 16:45:45] cmb@php.net
> [â¦] and 'EFBBBF3F' in hexadecimal. Why does it show up as '?'
Because that bytes are an UTF-8 BOM followed by a question mark.
Displaying this as ? is correct, but I wonder where that BOM comes
from.
> I have CHAR_AS_UTF8=TRUE in the additional connection properties
> in the ODBC Data Source Administrator.
Did you try with CHAR_AS_UTF8=FALSE?
Also, I suggest that you check whether that would work with
PDO_ODBC. I assume that you'd get the same results as with ODBC by
default, but setting the PDO::ODBC_ATTR_ASSUME_UTF8 attribute may
yield the desired results.
------------------------------------------------------------------------
[2021-03-18 15:28:27] tony at tonymarston dot net
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 '?'
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=80874
--
Edit this bug report at https://bugs.php.net/bug.php?id=80874&edit=1