I has a system, that makes query to a oracle database.
Each numeric column is using ‘,’ as decimal separator.
I tried different approaches and I did not succeed.
Makes a small program to TESTE using PDO directly withou YII, and the results are ok
<?php
$user = 'ws';
$pass = 'ws';
$charset = 'utf8mb4';
$dsn = "oci:dbname=localhost:1521/orcl";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_CASE => PDO::CASE_LOWER,
PDO::ATTR_STRINGIFY_FETCHES => true
];
$pdo = new PDO($dsn, $user, $pass, $opt);
// Configuring de ORACLE session to use dot as decimal separator
$stmt = $pdo->exec( "ALTER SESSION SET NLS_NUMERIC_CHARACTERS = '. '");
$sSql = ......
$stmt = $pdo->query( $sSql );
while ($row = $stmt->fetch())
{
echo $row['tot_item'] . "\n";
}
$pdo= null;
Result:
771.6
1834.8
1223.2
1157.4
========
In Yii
========
open database code:
$odb = new \yii\db\Connection([]);
$odb->masters = [
[ 'dsn' => $sDsnSec1, 'username' => $sUsuario, 'password' => $sSenha,
'attributes' => [ \PDO::ATTR_CASE => \PDO::CASE_LOWER,
\PDO::ATTR_EMULATE_PREPARES => false, \PDO::ATTR_STRINGIFY_FETCHES => false ] ],
[ 'dsn' => $sDsnSec2, 'username' => $sUsuario, 'password' => $sSenha,
'attributes' => [ \PDO::ATTR_CASE => \PDO::CASE_LOWER,
\PDO::ATTR_EMULATE_PREPARES => false, \PDO::ATTR_STRINGIFY_FETCHES => false ] ]
];
$odb->on( 'afterOpen', function ($event)
{
// Set DATE FORMAT
$event->sender->createCommand("ALTER SESSION SET NLS_DATE_FORMAT='DD/MM/YYYY HH24:MI:SS'")->execute();
// Set '.' decimal separator
$event->sender->createCommand("ALTER SESSION SET NLS_NUMERIC_CHARACTERS = '. '")->execute();
});
$odb->open();
the result is :
771,6
1834,8
1223,2
1157,4
Yii config:
'sourceLanguage' => 'en-US',
'language' => 'en-US',
'timeZone' => 'America/Sao_Paulo',
What is interfering so that the result is with the comma as a decimal separator?
How configure to get numbers with ‘,’ as decimal separator?