?
Solved

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

Posted on 2013-06-18
4
Medium Priority
?
1,087 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 58

Assisted Solution

by:Julian Hansen
Julian Hansen earned 668 total points
ID: 39255916
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 668 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 664 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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