Parsing JSON to MySQL table

前端 未结 1 836
孤街浪徒
孤街浪徒 2021-01-23 17:57

I\'m using Zend Framework (1.12) and I\'d like to create a table based on a JSON file. I\'ve already created the table and its fields (they\'re all longtext for now), all it has

1条回答
  •  抹茶落季
    2021-01-23 18:48

    Your json data has the top level key 'Actie', so you need to be looping through $my_arr->Actie.

    You can simplify your code to just:

    $actieurl = "http://creative3s.com/thomas/nmdad/actie.json";
    $my_arr = json_decode(file_get_contents($actieurl));
    
    $db = new Zend_Db_Adapter_Pdo_Mysql(array(
        'host' => 'localhost',
        'username' => 'root',
        'password' => NULL,
        'dbname' => 'zf-tutorial'
    ));
    
    foreach($my_arr->Actie as $row){
        $db->insert('testerdetest', (array)$row);
    }
    

    0 讨论(0)
提交回复
热议问题