0
我想創建一個PHP腳本,它會撕裂一個Json文件對其進行排序並將其發送到數據庫,但是我不會不明白爲什麼會發生這種情況:我曾經得到一個錯誤,說我超出了PHP的內存限制(將其設置爲無限制),但現在我得到一個超時錯誤。我有一種感覺,它是我的代碼而不是服務器,但我沒有看到任何錯誤,while循環不是無限循環。Infinate循環?遺漏了什麼?我不知道發生了什麼錯誤:500超時(不應該發生)
<?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";
}
?>
'count($ tagArray)'有沒有機會評估爲'0'?另外,你可能的意思是'$ tagsNum> $ minTags' – karthikr
我應該添加一個if語句來檢查它是否是。 – user2457491