G
G
Gura2015-11-07 18:56:26
PHP
Gura, 2015-11-07 18:56:26

How to import data from xml file into mysql database?

Hello to all toasts with a crust) I'm Gura, but unfortunately far from being a guru .. There was a need to find another solution.
There is an xml file (epg tv) whose structure is:

<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE tv SYSTEM "...">
<tv generator-info-name="TVH_W/0.751l" generator-info-url="....">
<programme start="20151026074500 +0300" stop="20151026080000 +0300" channel="958">
<title lang="ru">Текст текст текст</title>
</programme>
.
.
.
<programme start="20151026080000 +0300" stop="20151026081000 +0300" channel="958">
<title lang="ru">Текст текст текст </title>
</programme>
</tv>

The volume of such a file is 38MB (this is somewhere around 17,000 records).
There is a need to enter information into the mysql database once a week. Now there are 2 solutions:
  1. simple_html_dom - Where in the loop I will enter information into the database, which will create a large load on the database.
  2. And LOAD XML LOCAL INFILE:
    LOAD XML LOCAL INFILE 'tv.xml'
      INTO TABLE test
      ROWS IDENTIFIED BY '<programme>' 
    SET start=DATE_FORMAT(LEFT(start, 14),'%Y-%m-%d %H:%i'), 
    stop=DATE_FORMAT(LEFT(stop, 14),'%Y-%m-%d %H:%i'), title=SUBSTRING_INDEX(title, ' (', 1);
    - but this option generally knocks out the base, I think so because of the amount of information entered

Any idea what if you do something like sql dump file and load like "Import" in PHPmyadmin? Guys, advise something, in a more or less understandable language for self-taught.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-11-07
@Rsa97

When adding this amount of data, you can temporarily disable indexes so that they do not rebuild each time you add a row. If you make a database dump through mysqldump, you will see the ALTER TABLE ... DISABLE KEYS command before inserting data, after inserting - ALTER TABLE ... DISABLE KEYS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question