PHP脚本只会解析,也许1〜2的结果,但不完整的文件。 JSON文件中有大约200个结果。PHP不会完全解析JSON文件的所有结果
这里是php文件
$url = 'http://ironcentral.org/carnivore/api/nation_data/iron_nations';
$content = file_get_contents($url);
$json = json_decode($content, true);
$con = mysqli_connect("localhost", "user", "pass", "iron");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
foreach($json as $item) {
$sql = "INSERT INTO nations (nationid, ruler, nation, gov, religion, tech, infra, land, mode, resource1, resource2, strength, defcon, soldiers, tanks, cruise, nukes, slots) VALUES ('$item[nationid]','$item[ruler]','$item[nation]','$item[gov]','$item[religion]','$item[tech]','$item[infra]','$item[land]','$item[mode]','$item[resource1]','$item[resource2]','$item[strength]','$item[defcon]','$item[soldiers]','$item[tanks]','$item[cruise]','$item[nukes]','$item[slots]')";
}
mysqli_query($con, $sql) or die(mysqli_error($con));
mysqli_close($con);
做当选项3 [太阳17年10月4日:42:34.694326 2015] [:错误] [4468 PID] [客户端69.120.197.63:46043] PHP解析错误:语法错误,在第16行的/var/www/html/login/nations.php中出现意外的'$ inserts'(T_VARIABLE) 选项1有效,但后来我得到 你的SQL语法;检查对应于你的MySQL服务器版本的手册正确的语法使用近“我的信仰”,“17,121.50”,“8,999.99”,“1,100.001”,“对战模式”,“小麦”,“铁”,“123,530.4”在线1 – Ryahn
我的不好。我在那里留下了一个错误的逗号。我显然不能测试这个代码,所以有时候会偷偷溜走。 –
选项3不通过,除非通过 '解析错误:语法错误,意外'$插入'(T_VARIABLE)在/var/www/html/login/nations.php在线16' – Ryahn