im试图将多个JSON文件插入数据库(总共约20-30个,im现在使用2个进行测试)。所有文件将具有相同的格式。我以前将文件插入到HTML表中,所以我使用了相同的循环,因此我的脚本将目录中找到的所有JSON文件插入数据库中。但是,我遇到了一些错误1)“未定义的索引:注释”和2)表“ serverd.serverd”不存在。任何指导将不胜感激。我把括号移了一下,但是没有运气。
'<?php
$connect =mysqli_connect("reservation","-----","-----","serverD") or
die("could not connect");
$dir = "/Users/-----/Desktop/reserve/sql";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
foreach(glob("*.json") as $filename) {
$jsondata = file_get_contents($filename);
$data = json_decode($jsondata, true);
$Manufacturer = $data['Comments']['Manufacturer'];
$Model = $data['Comments']['Model'];
$BIOSFamily = $data['Comments']['BIOSFamily'];
$BIOSDATE = $data['Comments']['BIOSDate'];
$SerialNumber = $data['Comments']['SerialNumber'];
$sql= " INSERT INTO serverD(Manufacturer, Model, BIOSFamily, BIOSDate, SerialNumber)
VALUES('$Manufacturer' , '$Model' , '$BIOSFamily' , '$BIOSDate' , '$SerialNumber')";
$query=mysqli_query($connect, $sql) or die (mysqli_error($connect));
}
}
}
?>'