www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] XML to MySql Using PHP

  1. #1
    Join Date
    Feb 2012
    Posts
    30

    resolved [RESOLVED] XML to MySql Using PHP

    Hello,

    I have been trying to find a way to export data from an xml document and back into mysql. i have wrote the following code:

    PHP Code:
    $oDOM = new DOMDocument();
    $oDOM->loadXML(file_get_contents('cdocuments1290.xml'));
    foreach (
    $oDOM->getElementsByTagName('conferences') as $Conferences1)
    {

    $Subject=mysql_real_escape_string($Conferences1->getElementsByTagName('Subject')->item(0)->nodeValue);
    $Event=mysql_real_escape_string($Conferences1->getElementsByTagName('Event')->item(0).VALUE);

    }

    $sql "insert into `Conferences` (`Event`, `Subject`) values ('$Event', '$Subject')";
    $perform_insert mysql_query($sql) or die("<b>Data could not be entered</b>.\n<br />Query: " $query "<br />\nError: (" mysql_errno() . ") " mysql_error()) 
    The above code works perfectly if the xml is set in a different layout to what i want, this is the layout that works:

    [XML]
    <conferences>
    <Subject>134142832</Subject>
    <Event>More Time</Event>
    </conferences>
    [/XML]

    the layout i need to use is the following:

    [XML]
    <conferences>
    <Subject value="134142832" />
    <Event VALUE="More Time" />
    </conferences>
    [/XML]


    I've been stuck on this for a while now and wonder if anyone could help please?

    In the XML document theirs is about 300 separate XML's all looking like the above and all will need to be imported.

    Hope this makes sense.

    Many Thanks
    Last edited by thewebportfolio; 03-13-2012 at 03:41 AM.

  2. #2
    Join Date
    Nov 2002
    Posts
    2,632

  3. #3
    Join Date
    Feb 2012
    Posts
    30
    Thank you Spufi, i have tried that already and cannot get it to work, any ideas?

    Many Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles