【问题标题】:PHP - locale information gone after PDO connection (DB2)PHP - 在 PDO 连接后消失的语言环境信息 (DB2)
【发布时间】:2012-10-06 22:16:49
【问题描述】:

PHP 在使用 PDO 连接到 DB2 后丢失所有语言环境信息有什么原因吗?

连接后我总是需要重新设置区域信息。

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

【问题讨论】:

  • 您是否在同时运行其他 PHP 脚本(也可能使用 setlocale())的(多线程)网络服务器上?如果是这样,请务必阅读this note in the documentation
  • 我们使用 Linux 和 Apache MPM(默认设置)
  • 我无法复制您的问题。我正在运行 Apache 2.2.22 和 PHP 5.3.10 的 Ubuntu 12.04 LTS 上进行测试。当我执行 apache2 -l 时,我看到了 prefork.c。这是我的 PDO 连接命令: $this->db_connection = new PDO("odbc:DRIVER={iSeries Access ODBC Driver};SYSTEM=$this->he_database_server;PROTOCOL=TCPIP", $temp_username, $temp_password);

标签: php pdo db2 locale


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多