glendango Posted July 19, 2018 Share Posted July 19, 2018 (edited) Before i get slaughtered on stack i wanted to reask a question i cant get an answer to....sorry. XML Project. What is the pro way of handling xml data feed from a crm which i will eventually display the content on a searchable website….? Do you use simplexml or do you dump the ftp file into a database and then call what you need with php/html? Do you update a mysql database with a cron job / php script ? If so i want to overwrite the old data with the fresh data, is this possible? Why do we use simplexml? I ve tested it today and i like the way you can extract what you want from the .xml file ..so if its that good... Do I need a database at all if my script can display the raw xml without the need for a db..? What ive done so far is : Use simplexml on some basic files which worked fine but as soon I started using a ‘real’ xml file I coudnt get anything out of it.(currently asking feeder what is going on, waiting for answer) I cant find any straight advice on what pro devs do.. ive seen a lot on json as well which I like but all the crm houses still use xml feeds… Thanks in advance. Edited July 19, 2018 by glendango Quote Link to comment https://forums.phpfreaks.com/topic/307529-xml-php-mysql/ Share on other sites More sharing options...
requinix Posted July 20, 2018 Share Posted July 20, 2018 Let's make this simple: 1. Where is this XML coming from? Is it your own site? 2. How often does it change? 3. What do you want to accomplish with the data inside? Quote Link to comment https://forums.phpfreaks.com/topic/307529-xml-php-mysql/#findComment-1559856 Share on other sites More sharing options...
glendango Posted July 20, 2018 Author Share Posted July 20, 2018 1) Feed comes from a CRM which is a third party. I will be creating a website that uses the feed to display over 100 products from the feed. 2) The feed is updated every 1 hour. 3) The data is property for estate agents..so basically a web site for an estate agents. There are plugins for this on wordpress but i dont want to use them as i want full control of the data. hope this helps... Quote Link to comment https://forums.phpfreaks.com/topic/307529-xml-php-mysql/#findComment-1559861 Share on other sites More sharing options...
requinix Posted July 20, 2018 Share Posted July 20, 2018 Set up a cronjob that periodically downloads the feed and stores everything in the database. Stored in a way appropriate for a database - the idea is that you will keep it in sync with the data from the feed, not that you just dump what's in the feed into it. So it should check for existing records that are unchanged, existing records that are changed, and of course new records. "Periodically" is obviously once an hour after the feed updates. You should be nice to their servers and not fetch immediately after the update because other people might be doing that too. Instead, try to wait some random amount of time - perhaps 5-15 minutes after. Then the website serves from your database. That's all it has to care about. It does not need to know about how the data is getting there, just that it is there. Quote Link to comment https://forums.phpfreaks.com/topic/307529-xml-php-mysql/#findComment-1559862 Share on other sites More sharing options...
glendango Posted July 20, 2018 Author Share Posted July 20, 2018 (edited) many thanks... so what is simplexml for ? i thought the database option was most logical but got thrown by the use of this tool . also when it comes to insert/update the database , would i set up a php statement for every element of a property (there are 4 fileds (tables) and over 50 eleements. Do you hand write in every element to the code and the table titles? i dont mind doing this as once its done once thats it.. but interested in the logic of xml to database to website.... nb.. is simplexml used to display basic information from an rss / api type feed... ? you put the xml into a database when you need more control over data? Edited July 20, 2018 by glendango Quote Link to comment https://forums.phpfreaks.com/topic/307529-xml-php-mysql/#findComment-1559868 Share on other sites More sharing options...
glendango Posted July 20, 2018 Author Share Posted July 20, 2018 Also is best method to use php with the cron job or can you update db directly (using mysql on phpmyadmin) Quote Link to comment https://forums.phpfreaks.com/topic/307529-xml-php-mysql/#findComment-1559871 Share on other sites More sharing options...
requinix Posted July 20, 2018 Share Posted July 20, 2018 2 hours ago, glendango said: many thanks... so what is simplexml for ? i thought the database option was most logical but got thrown by the use of this tool . SimpleXML is for reading XML. That simple. What you do with it while you're reading XML is separate. 2 hours ago, glendango said: also when it comes to insert/update the database , would i set up a php statement for every element of a property (there are 4 fileds (tables) and over 50 eleements. I don't think so? I can't tell what you're talking about. 2 hours ago, glendango said: Do you hand write in every element to the code and the table titles? i dont mind doing this as once its done once thats it.. but interested in the logic of xml to database to website.... You read the XML using SimpleXML. That is how you get the data in the XML. You then copy that data into your database. And the website reads from the database. I'm not sure what's confusing about that. 2 hours ago, glendango said: nb.. is simplexml used to display basic information from an rss / api type feed... ? you put the xml into a database when you need more control over data? You put the XML into the database so that you don't have to keep reading the XML every time you want anything from it. And databases are just better at storing and retrieving data anyways. 1 hour ago, glendango said: Also is best method to use php with the cron job or can you update db directly (using mysql on phpmyadmin) A cronjob is just something that the system runs on a regular basis. In this case that "something" would be a PHP script, and it would do whatever it wanted, such as fetch the XML from the site and read it and stuff the data into a database and whatever. Quote Link to comment https://forums.phpfreaks.com/topic/307529-xml-php-mysql/#findComment-1559883 Share on other sites More sharing options...
glendango Posted July 20, 2018 Author Share Posted July 20, 2018 great thanks... you actually answered all my questions you couldnt understand at the end with your other answers.. SO database is better to store use simplexml to get the xml and then use php to insert the xml into a database..( a cron job can be set up to do this automatically) Sounds simple out loud but you would be amazed how hard it is to get this method confirmed as the correct way to do something... Even in massive big php books xml only gets about 1 page..... i suppose i didnt get answer onn how you put all the elements into the database , but iam guessing this is done by hand.... like this example... foreach ($xml->children() as $row) { $title = $row->title; $link = $row->link; $description = $row->description; $keywords = $row->keywords; $sql = "INSERT INTO Quote Link to comment https://forums.phpfreaks.com/topic/307529-xml-php-mysql/#findComment-1559885 Share on other sites More sharing options...
requinix Posted July 20, 2018 Share Posted July 20, 2018 It depends so much on the XML, but what you saw there would probably resemble something similar to what you need. 1 Quote Link to comment https://forums.phpfreaks.com/topic/307529-xml-php-mysql/#findComment-1559886 Share on other sites More sharing options...
Barand Posted July 20, 2018 Share Posted July 20, 2018 Most things in a simplexml array are a simplexml objects. It is often necessary to cast elements as string types EG $title = (string)$row->title; 1 Quote Link to comment https://forums.phpfreaks.com/topic/307529-xml-php-mysql/#findComment-1559888 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.