This is the whole script to check
SQL
CREATE TABLE `games` (
`gameid` int(11) NOT NULL auto_increment,
`gameuid` varchar(255) NOT NULL,
`gtitle` varchar(255) NOT NULL,
`userid` varchar(255) NOT NULL,
`gimg` varchar(500) NOT NULL,
`gprogress` int(11) NOT NULL,
`gearned` int(11) NOT NULL,
`gplatinum` int(11) NOT NULL,
`ggold` int(11) NOT NULL,
`gsilver` int(11) NOT NULL,
`gbronze` int(11) NOT NULL,
`glastup` varchar(255) NOT NULL,
`gtotaltrophies` int(11) NOT NULL,
PRIMARY KEY (`gameid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
php
<?php
include("../config.php");
function loadThisXmlFile($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)');
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
## store data as an output
$output = curl_exec($ch);
curl_close($ch);
## load stored data
$xml = @simplexml_load_string($output);
## return output as an xml file
return $xml;
}
## change the url to your own xml target
$player = loadThisXmlFile('http://www.psnapi.com.ar/ps3/api/psn.asmx/getGames?sPSNID=hawkiq');
foreach ($player->Game as $gameinfo) {
//clean info if it's from input / untrustworthy
$clean = array_map("mysql_real_escape_string",array($gameinfo->Id,$gameinfo->Title,"hawkiq",$gameinfo->Image,$gameinfo->Progress,$gameinfo->Title,$gameinfo->TrophiesCount->Platinum,$gameinfo->TrophiesCount->Gold,$gameinfo->TrophiesCount->Silver,$gameinfo->TrophiesCount->Bronze,$gameinfo->LastUpdated,$gameinfo->TotalTrophies));
//place each record into a storage array
$keep[] = "('" . implode("','", $clean) . "')";
}
//Your SQL (outside the foreach loop)
//The explode just parses the records to the VALUES clause of the query
$sql ="INSERT INTO `games` (
`gameuid` ,
`gtitle` ,
`userid` ,
`gimg` ,
`gprogress` ,
`gearned` ,
`gplatinum` ,
`ggold` ,
`gsilver` ,
`gbronze` ,
`glastup` ,
`gtotaltrophies`
)
VALUES (" .
implode(",",$keep)
. ")";
//test
//echo $sql;
//exit();
$query = mysql_query($sql)or die('Invalid query: ' . mysql_error());
?>