我正在尝试创建一个 PHP 脚本,它将撕开一个 Json 文件对其进行排序并将其发送到数据库,但是我不明白为什么会发生这种情况:我曾经收到一个错误,说我超出了 PHP 的 RAM 限制(将其设置为无限制)但现在我收到超时错误。我有一种感觉,它是我的代码而不是服务器,但我没有看到任何错误,而 while 循环不是无限循环。
<?php
//Set Ram Limit to Unlimited
ini_set('memory_limit', '-1');
//Improper Variables.
$tags = '';
$minTags = 1;
$value = '';
//Initialize Database Variables.
$host = 'localhost';
$username = 'icangame_dataa';
$password = '**********************************';
$dbname = 'icangame_data';
//Get Game Content
$linkFolder = $_POST['linkToFile'];
$file = '../games/'.$linkFolder.'/__metadata__.json';
$json = json_decode(file_get_contents($file), true);
//Take Apart the JSon
$width = $json['width'];
$height = $json['height'];
$author = $json['author'];
$thumbnail_url = $json['thumbnail_url'];
$description = $json['description'];
$controls = $json['controls'];
$developer = $json['developer'];
$name = $json['name'];
$developer_url = $json['developer_url'];
$tagsArray = $json['tags'];
//Process My Tags
$tagsNum = count($tagArray);
while ($minTags > $tagsNum)
{
$tagsTricky = "'.tags.'";
$minTagsTricky = "'".$minTags."'";
$value = $json[$tagsTricky[$minTags]];
$tags.=$value.' ';
$minTags++;
}
//Database Connection
$myCon = mysqli_connect($host, $username, $password, $dbname);
if (mysqli_connect_errno($myCon))
{
echo "Error Connection:".mysqli_connect_error();
}
//Checking if Item already exists.
$gameItem = mysqli_query($con,"SELECT $name FROM gameList");
if (!$gameItem == $name)
{
//Sending Data to Database.
mysqli_query($myCon, "INSERT INTO gameList (width, height, author, thumbnail_url, description, controls, developer, name, developer_url, tags)
VALUES ('$width', '$height', '$author', '$thumbnail_url', '$description', '$controls', '$developer', '$name', '$developer_url', '$tags')");
}
else
{
echo "Item ".$name." already exists! Sorry, someone beat you to it. ;c";
}
?>