本文介绍了PHP - 在PDO连接(DB2)之后的区域设置信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在连接到连接后,我总是必须再次设置区域设置信息。 p>

 <?PHP 
//设置区域设置信息
setlocale(LC_MONETARY,'en_US');

//打印位置信息
print_r(localeconv());

// Array
//(
// [decimal_point] =>。
// [thousand_sep] =>
// [ int_curr_symbol] => USD
// [currency_symbol] => $
// [mon_decimal_point] =&$。
// [mon_thousands_sep] =>,
/ / ...
//)

// ***************************** *******************
//创建服务器
$ connection = new PDO(odbc:server,'username','密码');
// ******************************************** ****

//创建连接后查看区域设置信息
print_r(localeconv());

// Array
//(
// [decimal_point] =>。
// [thousand_sep] =>
// [ int_curr_symbol] =>
// [currency_symbol] =>
// [mon_decimal_point] =>
// [mon_thousands_sep] =>
// ...
//
//)
?>


解决方案

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


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.

这篇关于PHP - 在PDO连接(DB2)之后的区域设置信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:34