I am trying to input data from a JSON API into a MySQL DB but I have an error.
This is the error.
Warning: Cannot use a scalar value as an array in C:\xampp\htdocs\simplehtmldom\example\scraping\example_scraping_imdb.php on line 8
Warning: Cannot use a scalar value as an array in C:\xampp\htdocs\simplehtmldom\example\scraping\example_scraping_imdb.php on line 9
Warning: Cannot use a scalar value as an array in C:\xampp\htdocs\simplehtmldom\example\scraping\example_scraping_imdb.php on line 10
Warning: Cannot use a scalar value as an array in C:\xampp\htdocs\simplehtmldom\example\scraping\example_scraping_imdb.php on line 11
Warning: Cannot use a scalar value as an array in C:\xampp\htdocs\simplehtmldom\example\scraping\example_scraping_imdb.php on line 12
Warning: Cannot use a scalar value as an array in C:\xampp\htdocs\simplehtmldom\example\scraping\example_scraping_imdb.php on line 13
Warning: Cannot use a scalar value as an array in C:\xampp\htdocs\simplehtmldom\example\scraping\example_scraping_imdb.php on line 14
Warning: Cannot use a scalar value as an array in C:\xampp\htdocs\simplehtmldom\example\scraping\example_scraping_imdb.php on line 15
Al those lines are the bind param statements in the PHP code.
Here is the code that I use (The JSON objects are nested):
<?php
$db = new PDO('mysql:host=localhost;dbname=wtd','root','');
$jsondata = file_get_contents('https://hugo.events/genre/pop/next/200/100');
$data = json_decode($jsondata, true);
$stmt = $db->prepare("insert into events values(?,?,?,?,?,?,?,?)");
foreach ($data as $row) {
$stmt->bindParam(1, $row['hits']['hits']['_id']);
$stmt->bindParam(2, $row['hits']['hits']['fields']['name']);
$stmt->bindParam(3, $row['hits']['hits']['fields']['start']);
$stmt->bindParam(4, $row['hits']['hits']['fields']['venue.location']);
$stmt->bindParam(5, $row['hits']['hits']['fields']['description']);
$stmt->bindParam(6, $row['hits']['hits']['fields']['header']);
$stmt->bindParam(7, $row['hits']['hits']['fields']['logo']);
$stmt->bindParam(8, $row['hits']['hits']['fields']['genres']);
$stmt->execute();
}
EDIT: Sample of JSON data:
https://ghostbin.com/paste/437q7
Hope someone has a sollution. Thanks in advance.