The other day I wrote a script which reads data from Active Directory and inserts it into a MS SQL database. The collation of the db is SQL_Lithuanian_CP1257_CI_AS, so, since the data from AD comes in Unicode, I used iconv() to convert it to Windows-1257 charset. The script does nothing fancy - only read->convert->insert.
The interesting thing is that when I execute the script via http (through Apache on Windows), it works just fine, all the language-specific characters appear in the db as they should. If I execute the same script through CLI, I end up with characters all messed up (in the db). Has anyone else experienced any similar differences between regular and CLI PHP versions? I was wondering if this could be a bug or something else?
Something odd
Moderator: General Moderators
Perhaps that's because cli version inherits environment of user running it (which is different from the environment of user running apache [LOCAL_SERVICE]). try to use setlocale(LC_ALL, "C"); in your script.
language-independent, standard, POSIX locale.
http://www.chemie.fu-berlin.de/chemnet/ ... tml#SEC321
http://www.chemie.fu-berlin.de/chemnet/ ... tml#SEC321
I tried adding
in the script, but it didn't help.
There must be somethign else causing this (or just a limitation of PHP CLI).
Code: Select all
setlocale(LC_ALL, 'C');There must be somethign else causing this (or just a limitation of PHP CLI).