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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php