BruceFarmerson Posted March 26, 2013 Share Posted March 26, 2013 I have several xml files in a folder on my webserver. I want to1. look in the folder2. get xml file names3. put file names into array4. loop those names into a mysql query5. have contents of all xml files inserted into db $files = glob('*.xml'); foreach($files as $file){ mysql_query("LOAD DATA INFILE '".$file."' INTO TABLE tablename ROWS IDENTIFIED BY ''"); } I've spent a couple of days looking for an example or tutorial but can't find anything online.Above is the best I can come up with.Any help appreciated Quote Link to comment https://forums.phpfreaks.com/topic/276193-upload-xml-files-in-a-folder-to-mysql-using-php-using-glob-and-array/ Share on other sites More sharing options...
exeTrix Posted March 27, 2013 Share Posted March 27, 2013 (edited) The only time I've ever used this is to load a CSV file into MySQL. I've checked the documentation and I can't see that XML is supported using this function. It looks relatively simple looking for a field delim and new lines. New lines identifying the end of the row. It's worth pointing out that XML does not need to follow this convention to be valid: <parent><child>Im a babeh!</child></parent><parent><child>Im a babeh!</child></parent> The above is valid XML but two records are on the same line. So LOAD DATA INFILE function wouldn't know where one row stops and the other begins. You might be able to fudge around it with adding custom delims but you may encounter problems. The safest solution would be to create a CSV using PHP, you'll have more control over handeling formatting issues and it'd only take a few lines using SimpleXMLIterator and SPLFileObject. If you need any more help then give me a shout Edited March 27, 2013 by exeTrix Quote Link to comment https://forums.phpfreaks.com/topic/276193-upload-xml-files-in-a-folder-to-mysql-using-php-using-glob-and-array/#findComment-1421364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.