Page 1 of 1

Something odd

Posted: Mon Aug 28, 2006 7:09 am
by Ree
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?

Posted: Mon Aug 28, 2006 10:20 am
by Weirdan
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.

Posted: Mon Aug 28, 2006 11:22 am
by Ree
Thanks, will check it later. "C" doesn't seem to be one of the allowed values though (at least not on Microsoft's site). What does "C" represent?

Posted: Mon Aug 28, 2006 12:00 pm
by Weirdan
language-independent, standard, POSIX locale.
http://www.chemie.fu-berlin.de/chemnet/ ... tml#SEC321

Posted: Mon Sep 04, 2006 12:14 pm
by Ree
I tried adding

Code: Select all

setlocale(LC_ALL, 'C');
in the script, but it didn't help.

There must be somethign else causing this (or just a limitation of PHP CLI).