简体   繁体   中英

PHP - locale information gone after PDO connection (DB2)

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] => 
//      ...
//
//    )
?>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM