fork download
  1. <?php
  2. $js = '{data":{"lbnref":"34558","message":"IRP Create Only (Disabled)","alert_id":"22521-trigger-617164","monitor_tool":"ipmonitor","flowName":"0 - Lancement depuis alerte Sentinel","central":"orchestration.lbn.fr","result":"No Action Taken","tag":"Association IRP non trouvee"}}';
  3.  
  4. $jsonData = json_decode($js, true);
  5. $jsonData = json_decode($jsonData['data'], true);
  6.  
  7. $tableName = 'profile';
  8. foreach((array)$jsonData as $id => $row){
  9. $insertPairs = array();
  10. foreach ((array)$row as $key=>$val) {
  11. $insertPairs[addslashes($key)] = addslashes($val);
  12. }
  13. $insertKeys = '`' . implode('`,`', array_keys($insertPairs)) . '`';
  14. $insertVals = '"' . implode('","', array_values($insertPairs)) . '"';
  15. $sql = "INSERT INTO `{$tableName}` ({$insertKeys}) VALUES ({$insertVals});\n" ;
  16. }
  17.  
  18. echo $sql;
Success #stdin #stdout #stderr 0.01s 24676KB
stdin
Standard input is empty
stdout
    
stderr
PHP Notice:  Undefined variable: sql in /home/RdlOGh/prog.php on line 18