Export from MySQL with relations to JSON (for CouchDB) with PHP -
Export from MySQL with relations to JSON (for CouchDB) with PHP -
i’m working on master thesis 1 of goals run tests , experiments against couchdb database , tune performance.
to need test data. i’ve created piece of php code generate simple relational info mysql database. tables are: customer product brand color checkout
i’ve made relations between illustration product , colorid , brandid , in checkout table i’ve relation customerid , productid.
i want export exclusively info construction , info relations json format couchdb. i’ve json string should contain each client attributes , purchase parameters product, , on.
i’m thinking like:
{ "customer": { "customerid" : "1", "firstname" : "somefirstname", "lastname" : "somelastname", "email" : "my@mail.com", "country" : "usa", "datecreated" : "11111111111111" } "purchase" : { "purchaseid" : "1", "product": { "productname" : "mightymouse", "productcolor": "blue", "productbrand" : "apple", "productprice" : "200", "checkoutdate" : "1111111111112" } "purchaseid" : "2", "product": { "productname" : "something nice", "productcolor": "yellow", "productbrand" : "google", "productprice" : "5000", "checkoutdate" : "11111111113333" } } }
it’s not right info construction i’ve shown that.
can done in php , if so, how create kind of “couchdb” ready json strings??
if haven’t explained myself clearly, please allow me know.
thank you sincere - mestika
php has function json_encode, can utilize convert php object json representation (and json_decode convert json string object). so:
use php database functions read info database.create object of stdclass:
$data = new stdclass;
fill object properties read database this:
$customer = new stdclass; $customer->customerid = "1" ... $data->customer = $customer;
encode generated object json_encode.
php mysql json couchdb rdbms
Comments
Post a Comment