Hello,
i use magicparser to import xlm data (actual car traffic info, updated every 15 minutes) into an mysql database
it seems that xml-entries are parsed TWICE.
i have comment-out the TRUNCATE because i would like to keep the already inserted entries
When i look in the database entries are parsed twice, but when i look at the xml-feed it doesn't show
what's wrong?
regards,
Marcel
<?php
require("MagicParser.php");
mysql_connect("xxxx","xxxx","xxxx") or die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());
$counter = 0;
unset($record);
unset($sDate);
function myRecordHandler($record)
{
$sDate = date("Y-m-d H:i:s");
global $counter;
global $sql;
$counter++;
mysql_query($sql);
$sql = "INSERT INTO xml_fileindex (wegnr, oorzaak, gevolg, van, naar, vansub, naarsub, hectostart, hectoeind, afstand, starttijd, link, trend, trendtekst,datumtijd)
VALUES (
'".mysql_real_escape_string($record["WEGNR"])."',
'".mysql_real_escape_string($record["OORZAAK"])."',
'".mysql_real_escape_string($record["GEVOLG"])."',
'".mysql_real_escape_string($record["VAN"])."',
'".mysql_real_escape_string($record["NAAR"])."',
'".mysql_real_escape_string($record["VANSUB"])."',
'".mysql_real_escape_string($record["NAARSUB"])."',
'".mysql_real_escape_string($record["HECTOSTART"])."',
'".mysql_real_escape_string($record["HECTOEIND"])."',
'".mysql_real_escape_string($record["AFSTAND"])."',
'".mysql_real_escape_string($record["STARTTIJD"])."',
'".mysql_real_escape_string($record["LINK"])."',
'".mysql_real_escape_string($record["TREND"])."',
'".mysql_real_escape_string($record["TRENDTEKST"])."',
'".mysql_real_escape_string($sDate)."')";
mysql_query($sql);
}
// empty table before inserting records
//$sql = "TRUNCATE xml_fileindex";
//mysql_query($sql);
// start parse XML to load new records
MagicParser_parse("{link saved}","myRecordHandler","xml|FILEINDEX/FILEDATA/MELDINGEN/MELDING/");
print "<p>Processed ".$counter." records.</p>";
print "<p>Last SQL statement was: ".$sql."</p>";
print mysql_error();
echo "Data Inserted!";
exit()
?>
David,
not sure which mysql_query($sql) u mean.
you mean the one after the TRUNCATE ?
Hello Marcel,
The XML as I just viewed it definitely only contains 1 MELDINGEN/MELDING/ record, so that looks fine. When you run your script, I see you have this line:
print "<p>Processed ".$counter." records.</p>";
How many records is that saying have been processed? The code for that looks fine.
But I notice that having commented out your TRUNCATE SQL, that you still have at line 14:
mysql_query($sql);
...this should fail, but whilst testing, it would be best to comment this out as well...
Cheers,
David.