Importare array in mysql

Arawan Omacha

Utente Attivo
2 Ott 2015
20
0
1
Buongiorno,
Ho un problema, ovvero, sto cercando di importare dei dati json all'interno di un database mysql, ma essendo che il json comprende delle array all'interno delle array non mi vengono importate, mi vengono importati solamente i dati che non sono array, ad esempio i valori dell'array "items" non vengono importati
Json:
JSON:
"shops": [
  {
"title": "B> Grapes",
"owner": "Hello Kitty",
"location": {
"map": "morocc",
"x": 148,
"y": 80
},
"creation_date": "2020-05-11T09:02:32Z",
"type": "B",
"items": [
  {
"item_id": 514,
"amount": 2000,
"price": 400
}
],
},

PHP
PHP:
<?
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$host="";
$user="";
$pass="";
$db="";
$connect= new mysqli($host,$user,$pass,$db) or die("ERROR:could not connect to the database!!!");



$f = file_get_contents('asd.json');
if(!function_exists('json_decode')) die('Errore!');
$feed = json_decode($f,true);


for($i=0; $i<count($feed['shops']); $i++)
{
    $sql = array();
        foreach($feed['shops'][$i] as $key => $value){
        
   $sql[] = (is_numeric($value)) ? "`$key` = $value" : "`$key` = '" . mysqli_real_escape_string($connect,$value) . "'";
    }

    $sqlclause = implode(",",$sql);
    
    $rs = mysqli_query($connect,"INSERT INTO market SET $sqlclause");
    print_r($key);
            
    

}

?>
 

Discussioni simili