473,503 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

import xml data into my mysql database

1 New Member
import data from a long xml file into my mysql database using php and xslt file give me errors

i have a long xml containing information that i need to import them into my mysql database.
to do so i write some sql queries with php language
i faced some problem with empty tags [bug with php5 and xml)

to resolve this bug, i writed an xslt file to remove the empty file.

the code is working fine in case of small xml file.
but when i apply the same code on a long and big xml file, it takes time and i didnt get any result (break code)

my code is
Expand|Select|Wrap|Line Numbers
  1. public function loadXML(){
  2.         $path = Yii::getPathOfAlias('webroot') . '/protected/files/';
  3.  
  4.         $filename = $path . 'loads.xml'; // the source xml file that contains the SIS information
  5.         $xsltFile = $path . 'clean.xsl'; // the xslt file that contains the xslt code that remove the empty tags
  6.         //$result = $path . 'test.xml';  // the output result file: SIS xml file without the empty tags
  7.         $result = $path . 'loads.xml';  // the output result file: SIS xml file without the empty tags
  8.  
  9.         // because the empty tags cause to insert empty and NULL values into database
  10.  
  11.  
  12. //  -------    run the xslt file that remove the empty element from the xml source file that contains the SIS information  --------
  13.         // Load the XML source
  14.         $xml = new DOMDocument;
  15.         $xml->load($filename);
  16.  
  17.         $xsl = new DOMDocument;
  18.         $xsl->load($xsltFile);
  19.  
  20.         // Configure the transformer
  21.         $proc = new XSLTProcessor;
  22.         $proc->importStyleSheet($xsl); // attach the xsl rules
  23.  
  24.         if ($xml_output = $proc->transformToXML($xml)) {
  25.  
  26.           file_put_contents($result, $xml_output);
  27.         } else {
  28.           trigger_error('Oops, XSLT transformation failed!', E_USER_ERROR);
  29.         } 
  30.  
  31. //  --------------------------------------------------------------------------------------------------------------------------------
  32.  
  33.         $sql='LOAD XML INFILE \'' . $result . '\' INTO TABLE stclass ROWS IDENTIFIED BY "<VwClass>"';
  34.         Yii::app()->db->createCommand($sql)->execute();
  35.         /*
  36.         $sql='LOAD XML INFILE \'' . $result . '\' INTO TABLE matiere ROWS IDENTIFIED BY "<vwClassSubjects>"';
  37.         Yii::app()->db->createCommand($sql)->execute();
  38.  
  39.         $sql='LOAD XML INFILE \'' . $result . '\' INTO TABLE student ROWS IDENTIFIED BY  "<VwRegisteredStudents>"';
  40.         Yii::app()->db->createCommand($sql)->execute();
  41.  
  42.         $sql='LOAD XML INFILE \'' . $result . '\' INTO TABLE usersectionsecurity ROWS IDENTIFIED BY "<vwUserSectionSecurity>"';
  43.         Yii::app()->db->createCommand($sql)->execute();*/
  44. }
  45.  

the xml file size is 216.336 KB
Nov 27 '13 #1
1 4768
Luuk
1,047 Recognized Expert Top Contributor
"the xml file size is 216.336 KB "
is this the size AFTER the xslt processing?, if not what is the size after the xslt processing?

"it takes time and i didnt get any result (break code)"
how long is this? did you wait long enough?
how many records are going to be inserted?
how does your table look like?
and what (how many) indexes are defined on that table?
how many memory, and what operating system?

hmm, what else can there be what might cause this.... ;)
Nov 29 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6249
by: mdh | last post by:
I am trying to learn the basics of MVC applications using a Tomcat infrastructure. I'm starting by building a simple application with: * a login.jsp page for a basic login form with a action...
8
31041
by: Johnny | last post by:
I was looking for information on how to import an excel file or other text file into a MySql database. I have done this with both access and SQL Server and am looking for a way to do this in...
5
3291
by: Kajol | last post by:
Hi All, can u plz tell me how to import data from mysql to another database. & how to export data from anotherdata base to mysql Thanx for ur Advice Regards Kajol
3
4902
by: Xerxes | last post by:
Hi, I would like to import the tables from MySQL database into Access database and I am not sure how to go about it. I tired to "Import External Data" from Access, selected "ODBC database" from...
1
2652
by: dimitri | last post by:
i try to copy data from excel into my MySql database which runs on a linux. i use MS Access to access the database. i need to optain the unique id number, and this is where i have some troubles....
7
4174
by: Randy | last post by:
Folks: We have a web-based app that's _really_ slowing down because multiple clients are writing their own private data into a single, central database. I guess the previous programmer did...
9
2837
by: asenthil | last post by:
Hai to all,, i had to tried to retrive and write a single row to a file from the database.. But dont know to write all the retrived rows to a file from the database.. how to do that... ...
3
4902
by: obkfixx | last post by:
hi everyone im new here.. and ive got this problem... actually im a newbie in programming so.. im gonna need every ounce of help. so here goes : i have a database in my localhost named hostel. But...
4
1835
by: gnawz | last post by:
Hi, I need a script that I can put in my admin panel to back up/restore, export/import a MySQL database. Something to use online, instead of PHPMyAdmin Somebody please help.
1
12117
by: santhanalakshmi | last post by:
Hi, I wrote some coding, to import excel data in mysql database using PHP Script? But my script, its not all inserting the excel data in mysql database. I don't know, what mistake did i made?...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.