php - Export MySQL table rows as individual files (specifically JSON) in one go -
i have on 750 json files need create mysql database table.
it wordpress "wp_options" table, mysql question.
the wp_options table has following properties.
option_id, option_name, option_value, autoload
the "option_name" become json file name.
i fine if "have to" rename each file name manually.
the "option_value" become json data.
is there way can more efficiently instead of creating empty json file each row , copying data base option_value json file?
my main concern 750 files make little weary miss or double on something, , information has exact.
note: i've read stack article (which closest find) @ http://goo.gl/rnv5cf. but, doesn't seem working expected given wordpress wp_options values think.
if needed this, , needed once, i'd run little php script locally.
assuming have grabbed table array (here i've called $wp_options
), iterate on using fopen
, fwrite
, fclose
make files. i've assumed want files have '.json' extensions can strip out.
foreach ($wp_options $wpo) { $newfile = fopen($wpo['option_name'].'.json', 'w'); // w=write mode fwrite($newfile, json_encode($wpo['option_value'])); fclose($newfile); }
the above untested, think work.
Comments
Post a Comment