Solved

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

Posted on 2013-06-18
4
1,025 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 57

Assisted Solution

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

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 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