0

I'm familiar with extracting data from an array and inserting it into MySQL. Unfortunately, I'm stuck on the syntax required to extract data from my JSON data and insert it into a MySQL database table. The MySQL database table has the same column names as the JSON data.

Any help is much appreciated. Thank you.

My example code:

$outputFile = "/tmp/scrapingjob-data{$scrapingJobId}.json";
try {
    $client->downloadScrapingJobJSON($scrapingJobId, $outputFile);

    // read data from file with built in JSON reader
    $reader = new JsonReader($outputFile);
    $rows = $reader->fetchRows();
    foreach($rows as $row) {
        // Import records into database.  I'm STUCK HERE.
    }
} 

My example JSON data:

{"title":"Nokia 123","price":"$24.99","description":"7 day battery"}
{"title":"ProBook","price":"$739.99","description":"14\", Core i5 2.6GHz, 4GB, 500GB, Win7 Pro 64bit"}
{"title":"ThinkPad X240","price":"$1311.99","description":"12.5\", Core i5-4300U, 8GB, 240GB SSD, Win7 Pro 64bit"}
{"title":"Aspire E1-572G","price":"$581.99","description":"15.6\", Core i5-4200U, 8GB, 1TB, Radeon R7 M265, Windows 8.1"}
Wyatt Jackson
  • 303
  • 1
  • 2
  • 11
  • Your code has a comment that it is using a "built in JSON reader", but there is no class called `JsonReader` built into PHP. As such, we have no idea what `$row` looks like - we could guess, but if we guess wrong, we've wasted both our time and yours. – IMSoP Jan 28 '23 at 18:55

0 Answers0