简体   繁体   English

PHP - PDO连接后的语言环境信息消失(DB2)

[英]PHP - locale information gone after PDO connection (DB2)

Is there any reason why PHP loses all locale information after connecting to DB2 with PDO? 在使用PDO连接到DB2之后,PHP是否有任何原因丢失所有语言环境信息?

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. 如果您使用的是Windows,则存在setlocale()无效的一般问题。 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. 我赢了7专业64位。 No other script were running at that time. 当时没有其他脚本正在运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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