Insert invalid json value
rodion-k opened this issue · comments
Rodion commented
Amp\Loop::run(function () {
$db = new \Amp\Mysql\Pool(...);
yield $db->query("CREATE TABLE IF NOT EXISTS amp_json (a varchar(255), b JSON)");
/** @var \Amp\Mysql\Statement $statement */
$statement = yield $db->prepare("INSERT INTO amp_json (a, b) VALUES (?, cast(? as json))");
$json = json_encode([1,2,3]);
yield $statement->execute([$json, $json]);
print_r(yield \Amp\Iterator\toArray(yield $db->query('select * from amp_json')));
$db->close();
});
Result is:
Array
(
[0] => Array
(
[a] => [1,2,3]
[b] => "base64:type251:WzEsMiwzXQ=="
)
)
This query works as expected with PDO as well as with mysql console client
Markus Staab commented
what is your expected result?
Rodion commented
what is your expected result?
Array
(
[0] => Array
(
[a] => [1,2,3]
[b] => [1,2,3]
)
)
Rodion commented
@trowski I expected what solution for this issue would be inserting correct value to mysql, but now above code works, but I see in mysql console client the following:
+---------+-------------------------------+
| a | b |
+---------+-------------------------------+
| [1,2,3] | "base64:type251:WzEsMiwzXQ==" |
+---------+-------------------------------+
Is this expected behavior?