问题
Is there any reason why PHP loses all locale information after connecting to DB2 with PDO?
I always have to set the locale information again after a connnection.
<?PHP
//set locale information
setlocale( LC_MONETARY,'en_US' );
//print location information
print_r(localeconv());
// Array
// (
// [decimal_point] => .
// [thousands_sep] =>
// [int_curr_symbol] => USD
// [currency_symbol] => $
// [mon_decimal_point] => .
// [mon_thousands_sep] => ,
// ...
// )
//************************************************
//create conenction to server
$connection= new PDO("odbc:server", 'username', 'password');
//************************************************
//see locale information after creating a connection
print_r(localeconv());
// Array
// (
// [decimal_point] => .
// [thousands_sep] =>
// [int_curr_symbol] =>
// [currency_symbol] =>
// [mon_decimal_point] =>
// [mon_thousands_sep] =>
// ...
//
// )
?>
回答1:
If you are on Windows, then there is general problem that setlocale() doesn't work. In my case it switched to base locale at random point in script, at the time of script was run. I had win 7 professional 64bit. No other script were running at that time.
来源:https://stackoverflow.com/questions/12921059/php-locale-information-gone-after-pdo-connection-db2