0

I have an XML feed coming in:

<?xml version="1.0" encoding="UTF-8"?><product>
<name>John</name>
<contact_email>[email protected]</contact_email>
<contact_telephone>01234 567</contact_telephone>
<url>www.johnsone.com.com</url></product>

I need to get this loaded to MySQL using php - have seen a few examples but all of them take a file saved locally.

My feed is taken from the internet so changes all of the time. Does anybody have any suggestions where to start?

Thanks

1
  • start from learning basic SQL commands. INSERT is one you need. then make yourself familiar with simplexml PHP extension. the rest is easy Commented Aug 11, 2010 at 16:02

4 Answers 4

1

First you'll need to define a data model. Then you'll need an xml parser to parse the feed, extract the data and populate your data model. Then you'll need to pass your model object to a DAO which writes the data to your database.

Sign up to request clarification or add additional context in comments.

Comments

0

If it's taken from the internet you can just do

<?php
$feedData = file_get_contents('http://mywebsite/myfeed.xml');
?>

Comments

0

if you want to parse the data and store then

  • create a table for product
  • parse the xml and get the fields
  • insert into db or update existing data

so, what's your problem?

Comments

0

To be a bit more specific: You'll obviously need to set up a table and database structure. I'm going to assume you have, or at least can figure out how to, set this up, and how to write to a database. If not, there are plenty of tutorials on that that should be plenty helpful. You'll need to use PHP's built-in MySQL library.

For parsing the XML you will probably want to use SimpleXML. It's not clear how your feed is coming in, but SimpleXML has the simplexml_load_string function that will let you pass it a string containing an XML document, however you get it, for parsing.

From there, you can just take the parsed XML and write it to your database. Any examples that use SimpleXML with a local file should be pretty easy to adapt using simplexml_load_string instead of simplexml_load_file, and doing whatever you're already (presumably) doing to get the data from this feed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.