Re: PDO native JSON / array support

From: Date: Wed, 26 Jul 2017 13:02:03 +0000
Subject: Re: PDO native JSON / array support
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-100047@lists.php.net to get a copy of this message
Hi, What would "support" exactly mean for a JSON type? Since JSON is a way of serialising data into a string, wouldn't all JSON values going into and out of the database just look like strings to the driver?
For Postgres's array types, some support for serialising and unserialising would definitely be useful, though, because the format is rather complex, particularly if you have multidimensional and sparse arrays. Obviously, users now have the workaround of transferring as JSON, but I know my last company had a pair of utility functions to attempt this in userland, which were known to be buggy in certain edge cases.
Regards,
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')
) .

« previous php.internals (#100047) next »