Jump to content

xml php mysql


glendango

Recommended Posts

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.

Link to comment
Share on other sites

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...

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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? 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.