好的 这里的编辑仍然有问题,但与更新代码之前不同
<?php
date_default_timezone_set('Europe/London');
$date = date('Y-m-d H:i:s', time());
$now = date('Y-m-d H:i:s');
$dbhost = "localhost";
$dbuser = "admin_cdm_clap";
$dbpass = "zdqUyFc5bAG1e6TWrIhijH3j7gB8xhmHI4q";
$db = "iTunesConnect";
$driveID = 562220229;
$connect = mysql_connect($dbhost,$dbuser,$dbpass) or die (mysql_error());
mysql_select_db($db);
$query = "SELECT `code` from `countries`";
$result = mysql_query($query) or die (mysql_error());
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$country=mysql_result($result,$i,"code");
$completeUrl = "https://itunes.apple.com/".strtolower($country)."/rss/toppaidapplications/limit=300/genre=6002/xml";
//echo $completeUrl.'<br>';
$xml = simplexml_load_file($completeUrl);
$entries = $xml->entry;
for ($a = 0; $a < 300; $a++) {
//$updated = $entries[$a]->updated;
$id = $entries[$a]->id->attributes('im', true)->id;
$bundle = $entries[$a]->id->attributes('im', true)->bundleId;
$cc = $entries[$a]->id;
$title = $entries[$a]->title;
$category = $entries[$a]->category['term'];
$nUpdated = microtime(true); //strtotime(substr($updated,0,10).' '.substr($updated, 11, 8))
$storeCode = substr($cc, 25, 2);
$storeCat = 6002;
if($id == $driveID){
$rankRec = "INSERT INTO rankings (id, rank, updated, store, category) VALUES (NULL, $a, $nUpdated, '$storeCode','$storeCat')";
mysql_query($rankRec) or die(mysql_error());
} else {
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
}
$i++;
}
?>
我现在得到以下错误;
注意:尝试获取/var/www/vhosts/createdm.com/httpdocs/iTunesConnect/iTunesRanking.php 第 24 行中的非对象属性致命错误:在第 24 行/var/www/vhosts/createdm.com/httpdocs/iTunesConnect/iTunesRanking.php 中的非对象上调用成员函数 attributes()
错误在这里
$id = $entries[$a]->id->attributes('im', true)->id;
它说attributes
函数是在非对象上调用的,这告诉我们->id
不是对象;它可能未设置。
所以这反过来告诉我们,要么XML有一个没有正确id
的条目,要么simplexml_load_file
认为有。
我会加强对对象的检查:
// This will save the current XML to a file, so that we may check
// the EXACT data we got, instead of requesting it again and, who
// knows?, get an intact copy, or a different version altogether
$dat = file_get_contents($completeUrl);
$fp = fopen('temp.xml', 'w');
fwrite($fp, $dat);
fclose($fp);
$xml = simplexml_load_file('temp.xml');
// Then...
$entries = $xml->entry;
for ($a = 0; $a < 300; $a++) {
if (!isset($entries[$a]))
die("Entries $a-300 were not found");
// if you discover that some small country has not 300 entries,
// then: (a) reactivate the error reporting which should have warned you,
// (b) replace the 300 with count($entries), or the for with a foreach loop.
// Moved $cc= here, it's more efficient.
$cc = $entries[$a]->id;
if (!is_object($cc))
die("Check entry $a's 'id' in temp.xml");
$id = $cc->attributes('im', true)->id;
$bundle = $cc->attributes('im', true)->bundleId;
// $cc = $entries[$a]->id;
$title = $entries[$a]->title;