Solved

What's the best way to create large XML files using PHP MySQL.

Posted on 2013-06-18
4
905 Views
Last Modified: 2013-06-22
Hi,

Need a quick answer...

I'm coding an end of day batch in PHP that loads all payments for specific products made via the website and bundles them up into XML files, for transmission to a third party for payment.

I just would like ideas as to the best way to do this...

I was about to launch into building arrays and then translating them into XML at the end of the loop?

Ideas? Experience?  Best practice?

Thanks,

Cris.
0
Comment
Question by:CrisThompsonUK
4 Comments
 
LVL 54

Assisted Solution

by:Julian Hansen
Julian Hansen earned 167 total points
ID: 39255916
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 167 total points
ID: 39255956
Here's what I might do (and if you want to show us the data, we can get more specific).

1. Throughout the data gathering period, I would add the data to a MySQL data base table (or maybe more than one table, depending on the data set).
2. At the time the data gathering period ends, I would stop adding data to the MySQL data base.  This stabilization could be achieved by LOCK or by disabling a script, or the process could continue data gathering using a new table.  The idea is to have a stable data set for the creating of the XML.
3. With the stable data set, I would SELECT all of the rows and fields that are needed in the XML document.  I would probably retrieve these with a fetch_object() method.
4. Build the subsets (nodes) of the XML document by using HEREDOC notation and string concatenation.
5. Wrap the XML document in the appropriate wrapper tags and write the document into a directory of the file system to save a copy.  Probably this XML document will be named in a way that will associate it with the date of the transactions.

The method of transmission to the 3rd party will be defined by the 3rd party.

If you can give us some more details (what is "large", who is the 3rd party, what is the format of the SQL tables and the XML document, how will you be transmitting the XML, etc.) maybe we can offer more specific guidance.

Best regards, ~Ray
0
 
LVL 15

Assisted Solution

by:Insoftservice
Insoftservice earned 166 total points
ID: 39268470
ALGO

1> Get data from your respective tables
select * from users
2> Create an array for the same with fetch_object()
 $arry[0]['text']='test';
 $arry[1]['text']='test1';
 $arry[2]['text']='test2';
 $arry[3]['text']='test3';
 
3> create xml using array_xml or create an customize one

<?php

$xml="<?xml version="1.0"?><rootNode>";

foreach($arr as $key=>$val)
{
   $xml .= "<text>".$val.</text>;
}
$xml .="</rootNode></xml>";

echo $xml;
?>
0
 

Author Closing Comment

by:CrisThompsonUK
ID: 39268556
Thanks guys.  The answer is really 'just do it.'

Done
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now