1

I use multiple servers to get data, but when i connect to a specific one, PHP lost the locale configuration.

So i pull data and format money numbers, but on the way of the process, if it connect to that server, then the rest of the process does not format money numbers anymore... money_format() command

localeconv();

Before

Array
(
    [decimal_point] => .
    [thousands_sep] => 
    [int_curr_symbol] => USD 
    [currency_symbol] => $
    [mon_decimal_point] => .
    [mon_thousands_sep] => ,
    [positive_sign] => 
    [negative_sign] => -
    [int_frac_digits] => 2
    [frac_digits] => 2
    [p_cs_precedes] => 1
    [p_sep_by_space] => 0
    [n_cs_precedes] => 1
    [n_sep_by_space] => 0
    [p_sign_posn] => 1
    [n_sign_posn] => 1
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
            [0] => 3
            [1] => 3
        )    
)

After

Array
(
    [decimal_point] => .
    [thousands_sep] => 
    [int_curr_symbol] => 
    [currency_symbol] => 
    [mon_decimal_point] => 
    [mon_thousands_sep] => 
    [positive_sign] => 
    [negative_sign] => 
    [int_frac_digits] => 127
    [frac_digits] => 127
    [p_cs_precedes] => 127
    [p_sep_by_space] => 127
    [n_cs_precedes] => 127
    [n_sep_by_space] => 127
    [p_sign_posn] => 127
    [n_sign_posn] => 127
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
        )
)

this is the script i ran:

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

How can this happen???? thanks

  • I saw that i already post this similar problem 2 years ago, but we have new servers for couople of months now but still get this problem. http://stackoverflow.com/questions/12921059/php-locale-information-gone-after-pdo-connection-db2 – user1529733 May 01 '14 at 12:07
  • i have done some test and if i run the script in a browser, it lost the configs, but if i run it in linux command line, it kept the configs, – user1529733 May 01 '14 at 12:37
  • We are in a LAMP environment – user1529733 May 01 '14 at 12:38

1 Answers1

0

localeconv() returns data based upon the current locale as set by setlocale().

According to the PHP documentation:

"The locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server API like IIS, HHVM or Apache on Windows, you may experience sudden changes in locale settings while a script is running, though the script itself never called setlocale(). This happens due to other scripts running in different threads of the same process at the same time, changing the process-wide locale using setlocale()."

Reference: https://www.php.net/manual/en/function.setlocale.php

May be you should consider to define the settings your self.

Samuil Banti
  • 1,735
  • 1
  • 15
  • 26