On 26 July 2017 14:02:03 BST, "Michał" <[email protected]> wrote:
>JSON should be automatically converted to proper type(s).
>
>$data = ['name' => 'John'];
>$sth = $dbh->prepare('INSERT INTO table (json_column) values (:data)');
>$sth->bindParam(':data', $data, PDO::PARAM_JSON); // new parameter
>
>
>SELECT json_column FROM table;
>$stmt->fetch(PDO::FETCH_ASSOC) should return
>
>array(
> [json_column] => array('name' => 'John')
>)
This feels like unnecessary magic to me, when you can already write this, and
have all the power and flexibility of the existing JSON functions:
$data = ['name' => 'John'];
$sth = $dbh->prepare('INSERT INTO table (json_column) values (:data)');
$sth->bindParam(':data', json_encode($data), PDO::PARAM_STRING);
As I say, array types are much more fiddly, so support for those would be great
- that could just be well-tested encode /decode functions.
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php