Solved

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

Posted on 2013-06-18
4
892 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 53

Assisted Solution

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

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

27 Experts available now in Live!

Get 1:1 Help Now