Bug #79217 [Opn]: Last character of a UTF-8 string gets messed up
| From: | cmb@php.net | Date: | Tue, 04 Feb 2020 17:19:55 +0000 |
| Subject: | Bug #79217 [Opn]: Last character of a UTF-8 string gets messed up | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225362@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79217&edit=1
ID: 79217
Updated by: cmb@php.net
Reported by: steve dot lloyd at gmail dot com
Summary: Last character of a UTF-8 string gets messed up
Status: Open
Type: Bug
Package: ODBC related
Operating System: Centos
PHP Version: 7.3.14
Block user comment: N
Private report: N
New Comment:
> The bug you referred to seemed to say this was patched but it is
> still an issue in PHP 7.4.
I rather think that some issues have been fixed, but likely not
all.
> The field I am querying is set to nvarchar(25). If I cast it as
> nvarchar(50) it works.
That's interesting, since
echo strlen('å éè´/ä»åºè被å»ç»'); // 28
echo strlen('gesp. für Arb.plan/Stückl'); // 27
So apparently either the driver or our binding (or maybe some
configuration setting) is confused by UTF-8.
I'm not sure how to debug this best. Is there something on CentOS
like the Windows ODBC tracing? A trace of a minimal reproduce
script could be very helpful.
Previous Comments:
------------------------------------------------------------------------
[2020-02-04 16:09:26] steve dot lloyd at gmail dot com
Interesing bit of information:
The field I am querying is set to nvarchar(25). If I cast it as nvarchar(50) it works.
test query:
----------
select cast(mtstb as nvarchar(50)) mtstb from sltschema.t141t
Results:
---------
Mtstb
å éè´/ä»åºè被å»ç»
å 任塿¸
å/BOMè被å»ç»
MPN:BOMæ¬å¤´å»ç»
gesp. für Besch./Lager
gesp. für Arb.plan/Stückl
------------------------------------------------------------------------
[2020-02-04 13:09:26] steve dot lloyd at gmail dot com
PDO has the same problem.
test script:
--------------------
try {
$pdo = new PDO("odbc:{$datasource}",$username, $password);
$query = "select * from sltschema.t141t";
$poo = $pdo->prepare($query);
$poo->execute();
$row = $poo->fetch(PDO::FETCH_ASSOC);
print_r($row);
}
catch (PDOException $e) {
echo "Connection failed : ". $e->getMessage();
}
Result:
---------------
Array
(
[MANDT] => 000
[SPRAS] => 1
[MMSTA] => 01
[MTSTB] => å éè´/ä»åºè被å»tc
[ZMODIFIEDTS] => 20200131152705439
[ZMODIFIEDTS_TEST] => 2020-01-31 15:27:05.4380000a
)
--------------------------
The bug you referred to seemed to say this was patched but it is still an issue in PHP 7.4. How do
I patch/resolve this issue?
------------------------------------------------------------------------
[2020-02-04 08:56:37] cmb@php.net
This seems to be related to bug #44278.
Can you try basically the same script with PDO_ODBC instead?
------------------------------------------------------------------------
[2020-02-03 22:06:52] steve dot lloyd at gmail dot com
Description:
------------
Last character of a UTF-8 string gets messed up. See stackoverflow URL in Test Script section. I
have tried this with multiple PHP versions. I have concluded it must be an issue with PHP ODBC
functions as it works fine in other languages (python, isql).
Test script:
---------------
https://stackoverflow.com/questions/59904479/last-character-issue-with-sap-hana-utf8-on-php
Expected result:
----------------
å éè´/ä»åºè被å»ç»
å 任塿¸
å/BOMè被å»ç»
MPN:BOMæ¬å¤´å»ç»
gesp. für Besch./Lager
gesp. für Arb.plan/Stückl
Actual result:
--------------
å éè´/ä»åºè被å»ad
å 任塿¸
å/BOMè被ader
MPN:BOMæ¬å¤´å»ç»
gesp. für Besch./Lager
gesp. für Arb.plan/Stüca
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79217&edit=1