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

2022-01-14 00:00:00 locale db2 php pdo

PHP 在使用 PDO 连接到 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] => 
//      ...
//
//    )
?>

推荐答案

如果你在 Windows 上,那么一般的问题是 setlocale() 不起作用.在我的情况下,它在脚本中的随机点切换到基本语言环境,在脚本运行时.我赢得了 7 个专业的 64 位.当时没有其他脚本在运行.

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.

相关文章