mysql tabellen naar xml via php
Ik wil twee tabellen combineren in een xml met de volgende fomat
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<Transaction>
<reference>070410171953</reference> //tabel 1
<customer>Tafel 8</customer> //tabel 1
<TransactionLines>
<product>Bier van het vat </product> //tabel 2
</TransactionLines>
<TransactionLines>
<product>Bier van het vat </product> //tabel 2
</TransactionLines>
<TransactionLines>
<product>Huiswijn wit glas </product> //tabel 2
</TransactionLines>
<TransactionLines>
<product>Psaronefri </product> //tabel 2
</TransactionLines>
<TransactionLines>
<product>Suflaki </product> //tabel 2
</TransactionLines>
</Transaction>
<reference>070410171953</reference> //tabel 1
<customer>Tafel 8</customer> //tabel 1
<TransactionLines>
<product>Bier van het vat </product> //tabel 2
</TransactionLines>
<TransactionLines>
<product>Bier van het vat </product> //tabel 2
</TransactionLines>
<TransactionLines>
<product>Huiswijn wit glas </product> //tabel 2
</TransactionLines>
<TransactionLines>
<product>Psaronefri </product> //tabel 2
</TransactionLines>
<TransactionLines>
<product>Suflaki </product> //tabel 2
</TransactionLines>
</Transaction>
Deze code werkt maat ik moet de 30sec timeout op de server uitzetten, dat kan ik op mijn local maar niet op de online server.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
mysql_connect("localhost", "root", "" );
mysql_select_db("pos");
$sql1 = "SELECT reference, customer FROM receipts ";
$result1 = mysql_query($sql1) or die ( mysql_error() );
$xml_output = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\n";
$xml_output .= "<Data>\n";
while ($row1 = mysql_fetch_assoc($result1) )
{
$receiptsreference=$row1['reference'];
$xml_output .= "<Transactions>\n";
$xml_output .= "<reference>" . $row1['reference']. "</reference>";
$xml_output .= "<customer>" . $row1['customer'] . "</customer>\n";
$sql2 = "SELECT product FROM orders WHERE reference = $receiptsreference";
$result2 = mysql_query($sql2) or die ( mysql_error() );
while ($row2 = mysql_fetch_assoc($result2) )
{
$xml_output .= "<TransactionLines>";
$xml_output .= "<product>" . $row2['product']. "</product>";
$xml_output .= "</TransactionLines>\n";
}
$xml_output .= "</Transactions>\n";
}
$xml_output .= "</Data>";
$XMLFile = fopen("myxmlfile.xml", "w");
fwrite($XMLFile, $xml_output);
fclose($XMLFile);
?>
mysql_connect("localhost", "root", "" );
mysql_select_db("pos");
$sql1 = "SELECT reference, customer FROM receipts ";
$result1 = mysql_query($sql1) or die ( mysql_error() );
$xml_output = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>\n";
$xml_output .= "<Data>\n";
while ($row1 = mysql_fetch_assoc($result1) )
{
$receiptsreference=$row1['reference'];
$xml_output .= "<Transactions>\n";
$xml_output .= "<reference>" . $row1['reference']. "</reference>";
$xml_output .= "<customer>" . $row1['customer'] . "</customer>\n";
$sql2 = "SELECT product FROM orders WHERE reference = $receiptsreference";
$result2 = mysql_query($sql2) or die ( mysql_error() );
while ($row2 = mysql_fetch_assoc($result2) )
{
$xml_output .= "<TransactionLines>";
$xml_output .= "<product>" . $row2['product']. "</product>";
$xml_output .= "</TransactionLines>\n";
}
$xml_output .= "</Transactions>\n";
}
$xml_output .= "</Data>";
$XMLFile = fopen("myxmlfile.xml", "w");
fwrite($XMLFile, $xml_output);
fclose($XMLFile);
?>
Hoe kan ik de script beter, sneller maken zodat niet met de timeout error heb te maken?
Bij voorbaat dank Dimitris
Gewijzigd op 16/04/2011 12:17:28 door Dimi orla
2. Door niet het principe van "string plakken" te gebruiken
http://www.php.net/DOM
http://www.php.net/xmlwriter
3. Je te verdiepen in de mogelijkheden van mysql
maar dan nog zal je tegen de time out aan kunnen lopen
m.a.w. je moet dit niet laten lopen via de webserver