php - Insert JSON into MySQL. -


I have .json file [categories.json]

like

 after 
{ "apple": [ "fruit", "15"], "cat": [ "animal", "400"], "pumpkin": [ "vegetables", "20"], "orange": [ "fruit", "30"]}

I want to insert json object in mysql using such loop php are

  | ___ id__ | ___ product__ | _____ type _____ | __price__ | | 1 | Apple Fruit | 15 | | 2 | Cat | Animals | 400 | 3 | Pumpkin | Vegetables | 20 | | 4 | Orange | Fruit | 30 |  

How do you thank me

  $ File = 'www.mysite.com/categories.json'; $ Data = json_decode (file_get_contents ($ file) is true); {$ SQL = "Join in Product"; Foreach (dollar data as $ line $ product = & gt;); .. $ Sql ​​= "Set product = ''. Mysql_real_escape_string ($ product)" ', type =' '.. Mysql_real_escape_string ($ line [0]) "', price =" mysql_real_escape_string ($ line [1]); Mysql_query ($ sql); } // Expecting your ID field in Auto DB  

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -