strzlee / JsonDB.class.php

JSON Databaseclass. Handle JSON-Files like a very, very simple DB.
Do What The F*ck You Want To Public License
93 stars 47 forks source link

[Question] Can the JSON data file be converted to data file? #5

Closed nullifiedaccount3 closed 10 years ago

nullifiedaccount3 commented 10 years ago

Is there a method to convert the JSON database to sql for export it to MySQL or other relational database?

nullifiedaccount3 commented 10 years ago

Being more specific

strzlee commented 10 years ago

it's not a miracle. Use json_decode and then construct a insert statement using the values of the array.

Here's a simplified php script:

con = mysql_connect("localhost","username","password");
mysql_select_db('your_database',$con);

$result = json_decode($jsonData);
foreach($result as $key => $value) {
if($value) {
    mysql_query("INSERT INTO tablename (id, foo, bar) VALUES ($value->id, $value->doo, $value->bar)");
}
}

Additionally there a many tools out there which can convert json files into sql statements vice versa.

nullifiedaccount3 commented 10 years ago

Thank you.