I have had MagicParser for some time, has there been any version upgrades?
Hi David,
I have a strange problem. The script was working fine and it returns all of the feed records to screen before inserting into a database.
However, when it inserts into my database, it inserts all records except the last one and I cannot figure out why? Any ideas?
Hi travelfrog,
That sounds like maybe your call to mysql_query() is slightly out of position; if you'd like to post your myRecordHandler() code into a post i'll check it out for you...
Cheers,
David.
//Construct the INSERT query
function myRSSRecordHandler($item)
{
global $EAv;
$time = time();
print('<pre>');
print($item["BZP-ID"].' - Property For Rental Uploaded to MySql<br />');
$EAv->query(" INSERT INTO blue_zone_property_xml_for_rent (prop_id, prop_url, prop_code, prop_ref_name, prop_image, prop_district, prop_town, prop_type, prop_area, prop_area_plot, prop_rooms, prop_bathrooms, prop_business, prop_curr, prop_price_rent, prop_price_sell, prop_desc, timestamp, agent, prop_rental_period)
VALUES ('".$item["BZP-ID"]."',
'".$item["PROPERTY-URL"]."',
'".$item["BZP-ID"]."',
'".$item["PROPERTY-NAME"]."',
'".$item["PROPERTY-IMAGE"]."',
'".$item["PROPERTY-REGION"]."',
'".$item["PROPERTY-CITY"]."',
'".$item["PROPERTY-TYPE"]."',
'NULL',
'NULL',
'".$item["PROPERTY-BEDROOMS"]."',
'".$item["PROPERTY-BATHROOMS"]."',
'".PROP_BUSINESS."',
'".PROP_CURR."',
'".$item["PROPERTY-PRICE-FROM"]."',
'NULL',
'".$item["PROPERTY-DESCRIPTION"]."',
'$time',
'".AGENT."',
'NULL')
");
}
//Call Magic Parser and let myRecordHandler load each item into the database
MagicParser_parse("string://".$xml,"myRSSRecordHandler","xml|PROPERTIES/PROPERTY/");
Hi,
Yes thanks - apologies for the delay in your post appearing I check all posts and comments before publishing in order to protects customers information / sites / links etc....
The code looks structurally fine - so the first thing I would do is check to see if the last entry generates a MySQL error for whatever reason. I see that you're using a database object $EAv so you might need to check the documentation for that in terms of how you go about detected and displaying an error - but assuming that it's using standard MySQL library calls internally you might get visibility of any error simply by adding the following code on the last line of your myRSSRecordHandler() function:
if (mysql_error()) print "<p>MySQL Error: ".mysql_error()."</p>";
Possibilities are that it's a duplicate key; or if your table definition has NOT NULL numeric types with no default and the feed content is not valid for that field type for example...
Hope this helps!
Cheers,
David
MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's even a portable gas barbecue!',
'1360241204',
'Blue Zone Property.',
' at line 18
MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 're in Heaven! This apartment is situated in a small paradise, with stunning view' at line 18
MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's facilities. It is 5 minutes by car from the historical centre of Lagos, the re' at line 18
Hi,
Ah - I should have spotted that in your original code - the error indicates mal-formed SQL, which is happening because the SQL is being constructed without escaping characters such as ' in the data. To fix this, use mysql_escape_string() around each variable used in construction of the SQL, e.g.:
$EAv->query(" INSERT INTO blue_zone_property_xml_for_rent (prop_id, prop_url, prop_code, prop_ref_name, prop_image, prop_district, prop_town, prop_type, prop_area, prop_area_plot, prop_rooms, prop_bathrooms, prop_business, prop_curr, prop_price_rent, prop_price_sell, prop_desc, timestamp, agent, prop_rental_period)
VALUES (
'".mysql_escape_string($item["BZP-ID"])."',
'".mysql_escape_string($item["PROPERTY-URL"])."',
'".mysql_escape_string($item["BZP-ID"])."',
'".mysql_escape_string($item["PROPERTY-NAME"])."',
'".mysql_escape_string($item["PROPERTY-IMAGE"])."',
'".mysql_escape_string($item["PROPERTY-REGION"])."',
'".mysql_escape_string($item["PROPERTY-CITY"])."',
'".mysql_escape_string($item["PROPERTY-TYPE"])."',
'NULL',
'NULL',
'".mysql_escape_string($item["PROPERTY-BEDROOMS"])."',
'".mysql_escape_string($item["PROPERTY-BATHROOMS"])."',
'".PROP_BUSINESS."',
'".PROP_CURR."',
'".mysql_escape_string($item["PROPERTY-PRICE-FROM"])."',
'NULL',
'".mysql_escape_string($item["PROPERTY-DESCRIPTION"])."',
'$time',
'".AGENT."',
'NULL')
");
That should be all it is...
Cheers,
David.
David,
Thank you very much. That was the problem.
Hi travelfrog,
Not at all - it's been totally stable! I do have some specific versions to handle certain anomalies and other conditions and work-arounds (such as ways to handle mal-formed data) so if you ever encounter something that you don't seem to be able to parse "out of the box" let me know as I might have a mod that will help...
Cheers,
David.