我遇到了一个奇怪的情况,我不确定如何解决它。
我在教条中得到了一个格式看起来很奇怪的查询结果。
我使用doctrine来执行下一个例子的查询:
$query = "select ... from ..."
$stmt = $this->oracleDB->prepare($query);
(This oracleDB is configured in the config.yml with "charset: ISO-8859-1" and "driver: oci8")
$stmt->bindValue(1, $variable, "...");
more binds...
$stmt->execute();
$results = $stmt->fetchAll();
大部分时间结果都是法线并且json_encode有效,但有时我会得到类似下一个的结果:
dump($results);
array:1 [▼
0 => array:6 [▼
"BLA1" => "xx"
"BLA2" => "XX"
"BLA3" => "XX"
"BLA4" => "XX"
"BLA5" => b"XX"
"BLA6" => "XX"
]
]
var_dump($results);
array (size=1)
0 =>
array (size=12)
'BLA1' => string 'XX' (length=2)
'BLA2' => string 'XX' (length=2)
'BLA3' => string 'XX' (length=2)
'BLA4' => string 'XX' (length=2)
'BLA5' => string 'X�X' (length=3)
'BLA6' => string 'XX' (length=2)
dump(json_encode($results));
false
如果我取消设置BLA5,json_encode效果很好。
unset($result[0]['BLA5']);
dump($result);
array:1 [▼
0 => array:5 [▼
"BLA1" => "xx"
"BLA2" => "XX"
"BLA3" => "XX"
"BLA4" => "XX"
"BLA6" => "XX"
]
]
dump(json_encode($results));
"[{"BLA1":"XX","BLA2":"XX","BLA3":"XX","BLA4":"XX","BLA6":"XX"}] ◀"
有什么想法吗?
答案 0 :(得分:0)
我原本希望拥有字符集ISO-8859-1的数据库,但实际上并非如此。一切尽在掌握之中。 THX!