API call via curl, json results in csv or mysql
===

I am very new to PHP, I need to call a api via curl and parse the results into a format that I can import into a data base.  How do I save the results as a csv or push it directly into a database?

Thanks

api call receiving these results

[{"mac":"AC86740410B8","siteId":"1032","name":"main-rtr","desc":"","loc":{"lat":-25.887635,"lng":28.150488,"levelId":0,"source":"manual"},"lrrt":1,"lrne":4}]

this is my code

    $ch = curl_init();
    $fp = fopen("data.txt", "a+");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, 'http://theapi.com/');
    curl_setopt ($ch, CURLOPT_USERPWD, "username:password");
    curl_setopt ($ch, CURLOPT_FILE, $fp);
    CURLOPT_HTTPHEADER >= array('Content-type: application/json');
    $json = ('data.txt');
    //json_decode($json, true);
    //$data = json_decode(file_get_contents('data.txt'), true);
    var_dump(json_decode($json));
    var_dump(json_decode($json, true));
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);