Something odd

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Something odd

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

language-independent, standard, POSIX locale.
http://www.chemie.fu-berlin.de/chemnet/ ... tml#SEC321
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post 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).
Post Reply