parse json from url using php and save in mysql db -
i've json response web service
{ "success":true, "timestamp":1503291248, "quotes":{ "sad":"abc", "love":"xyz", "friendship":"some", "enmity":"lorem ipsum", ... //indicates there lot more categories } }
i have tried echo data using script
<?php $url = 'my_url'; $content = file_get_contents($url); $json = json_decode($content, true); foreach ( $json $idx=>$json ) { echo $idx; } ?>
this prints
successtermsprivacytimestampsourcequotes
but getting empty response, how can echo/save above josn data in mysql?
<?php $url = '{ "success":true, "timestamp":1503291248, "quotes":{ "sad":"abc", "love":"xyz", "friendship":"some", "enmity":"lorem ipsum", ... //indicates there lot more categories } }'; $content = file_get_contents($url); $json = json_decode($content, true); foreach ( $json $idx=>$json ) { if(is_array($json)) { foreach($json $iidx=>$jjson) { echo $iidx.":".$jjson; } } else { echo $idx.":".$json; } } $ins_qry = 'insert json_table(jsonvalues) values ("'.$json.'")'; $exec_qry = mysqli_query($link,$ins_qry); ?>
this print json data. save json data in mysql, can directly insert $json
value text column of mysql table.
Comments
Post a Comment