Article

UTF-8 characters are not stored correctly in a UTF-8 OpenEdge database by PHP

Information

 
Article Number000090964
EnvironmentCentOS RedHat Oracle Linux 5.x 6.x 7.x 64 bit
OpenEdge 10.2B06 and higher
OpenEdge 11.x
PHP 5 and 7
Question/Problem Description
UTF-8 characters are not stored correctly in a UTF-8 OpenEdge database by PHP
Steps to Reproducecreate a UTF-8 OpenEdge database having a table character field
insert a non Western UTF-8 character into the OpenEdge table character field through PHP
Clarifying Information
PHP and the related ODBC connection are configured to use UTF-8

OpenEdge database is configured to use UTF-8

The SQL statement used in the PHP code is like:

insert into PUB.TableName (some_ID, columnName) values (7, '品')

Executing an ODBC insert statement outside of PHP with:

$DLC/bin/proenv
export LD_LIBRARY_PATH=$DLC/lib:$DLC/odbc/lib
export ODBCINI=/etc/odbc.ini
cd $DLC/odbc/samples/example
./example
./example DataDirect Technologies, Inc. ODBC Example Application.
Enter the data source name : Progress
Enter the user name : sysprogress
Enter the password : sysprogress
Enter SQL statements (Press ENTER to QUIT)
SQL> insert into PUB.TableName (some_ID, columnName) values (7, '品')


using the same ODBC connection used by PHP insert the correct character 品 in the database.
Error MessageInstead of a single Chinese character (encoded in 3 bytes by UTF-8) 3 garbage characters are inserted in the OpenEdge database when the Chinese character is entered through PHP.
Defect/Enhancement Number
Cause
PHP unified ODBC and PHP PDO ODBC do not support Unicode. Those PHP ODBC libraries are using ANSI ODBC APIs (SQLxxxA APIs) instead of the Unicode ODBC API (SQLxxxW APIs)"

More information available on https://www.progress.com/tutorials/odbc/unicode

The reason UTF-8 works with PHP when using Mysql (another type of database often used with PHP) is because MySQL does not use 'odbc_do' (unified ODBC PHP library) but for example 'mysqli_query' from a different PHP library (mysqli). There is also more than one PHP library available for connecting to MySQL, such a custom PHP extension does not exist for OpenEdge. (only the generic PHP unified ODBC and PHP PDO libraries can be used for OpenEdge ODBC connections from within PHP)
 
Resolution
None at this time.
Workaround
Using a different technology than PHP (either OpenEdge Webspeed, Java JSP, another web scripting language, etc ...) having better support for (Chinese) multi byte characters. 
 
Notes
Attachment 
Last Modified Date8/14/2018 1:35 PM


Feedback
 
Did this article resolve your question/issue?

   

Your feedback is appreciated.

Please tell us how we can make this article more useful. Please provide us a way to contact you, should we need clarification on the feedback provided or if you need further assistance.

Characters Remaining: 1025