Re: PDO native JSON / array support

From: Date: Wed, 26 Jul 2017 15:43:14 +0000
Subject: Re: PDO native JSON / array support
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-100049@lists.php.net to get a copy of this message
On Mi, 2017-07-26 at 15:02 +0200, Michał 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') > ) Mind that such conversions are not 100% reliable: php > var_dump(json_decode('{"a": 10.0000000000000000001}')); object(stdClass)#1 (1) {   ["a"]=>   float(10) } php > echo json_encode(json_decode('{"a": 10.0000000000000000001}')); {"a":10} php > var_dump(json_decode(json_encode(json_decode('{"a": 10.0000000000000000001}')))); object(stdClass)#1 (1) {   ["a"]=>   int(10) } johannes

« previous php.internals (#100049) next »