Search code examples
phpmysqldb2ibm-midrangeunixodbc

UTF-8 SELECT IBM i DB2 throught unixODBC php PDO Debian 9 in CLI php


I have a problem, very very picky.

I have a LAMP server which is connected to an IBM i (AS400) throught unixODBC. PHP execute sql on IBM i throught ODBC connection on IBM i.

I want to do a simple SELECT in my databse. It's work very well when the script is executed by a navigator (apache), but when the script is executed by CLI (php example.php) and when i have special characters like : Ô ô é à @ etc in my record PDO return NULL. And when i execute the script in my Web browser all the special characters are okay.

I don't understand why. I put 'CHARSET=UTF-8' in my DSN PDO connection.

I think this bug is related to : iSeries Access ODBC Driver with unixodbc on Debian - Invalid UTF-8 characters being returned from iSeries because when I SELECT with HEX(field) i have the hexa from browser and CLI.

PHP latest version (7.4.6), Debian 9.


Solution

  • As per comment thread, the cause of the issue was that when running from the command-line shell and php CLI, the shell was not correctly configured for UTF-8 for the correct locale (country etc).