-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
- 0 replies
- 7 views
-
Russia is dodging western sanctions by legalizing gray imports
By Karthik Mudaliar,
- 17 replies
- 3 views
-
- 8 replies
- 1,944 views
-
Save 96% off a lifetime plan to iBrave Cloud Web Hosting — or alternative deal
By News Staff,
- ibrave
- web hosting
- (and 9 more)
- 0 replies
- 4 views
-
Save 96% off a lifetime subscription to iBrave Cloud Web Hosting + $20 Store Credit
By News Staff,
- ibrave
- neowin deals
- (and 9 more)
- 0 replies
- 5 views
-
Question
Tjcrazy
Hey guys,
Got a bit of an issue importing a large xml into my mysql database.
I've got this xml file, from lastfm which I need to import. Theres a limit to 200 tracks per page, so I'll have to change the page parameter to 2,3,4,5 etc.
I've tried this php script, but it takes a long time to execute and it stops at number 10199
<?php
//DBCONNECTION
$total=0;
$n=1;
while($n<2320) {
$url = 'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=bbcradio1&api_key=c910b0bc1e2d4e64964ebcd2d69c255c&limit=200&page='.$n;
if(!$xml = simplexml_load_file($url)) {
echo 'Unable to load XML file';
exit();
} else {
$i=0;
while ($i < 200) {
foreach($xml as $recenttracks) {
$artist = $recenttracks->track[$i]->artist[0];
$name = $recenttracks->track[$i]->name[0];
}
foreach($xml->recenttracks[0]->track[$i]->date[0]->attributes() as $a => $b) {
$date = $b;
}
$artist = mysql_real_escape_string ($artist);
$name = mysql_real_escape_string ($name);
$date = mysql_real_escape_string ($date);
echo 'Number: '.$total.' n: '.$n.' i: '.$i.'<br />';
echo $date.'<br />';
echo $name.'<br />';
echo $artist.'<br /><br />';
$i++;
$total++;
mysql_query("INSERT INTO songs (Artist, Title, Time, DJ) VALUES ('$artist', '$name', '$date', 'Unknown')") or die(mysql_error());
}
}
$n++;
}
?>
[/CODE]
Has anyone got any ideas how I can import these 200,000 tracks from XML into my mySQL database?
Thanks a lot!
Link to comment
Share on other sites
9 answers to this question
Recommended Posts