Solved

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

Posted on 2013-06-18
4
869 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 51

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This article discusses how to create an extensible mechanism for linked drop downs.
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.

707 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

13 Experts available now in Live!

Get 1:1 Help Now