Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
require_once 'XML/Query2XML.php';
3
require_once 'MDB2.php';
4
$query2xml = XML_Query2XML::factory(MDB2::factory('mysql://root@localhost/Query2XML_Tests'));
5
 
6
require_once 'Log.php';
7
$debugLogger = Log::factory('file', 'case05.log', 'Query2XML');
8
$query2xml->enableDebugLog($debugLogger);
9
 
10
$query2xml->startProfiling();
11
 
12
 
13
$dom = $query2xml->getXML(
14
    "SELECT
15
         *
16
     FROM
17
         customer c
18
         LEFT JOIN sale s ON c.customerid = s.customer_id
19
         LEFT JOIN album al ON s.album_id = al.albumid
20
         LEFT JOIN artist ar ON al.artist_id = ar.artistid
21
     ORDER BY
22
         c.customerid,
23
         s.saleid,
24
         al.albumid,
25
         ar.artistid",
26
    array(
27
        'rootTag' => 'music_store',
28
        'rowTag' => 'customer',
29
        'idColumn' => 'customerid',
30
        'elements' => array(
31
            'customerid',
32
            'first_name',
33
            'last_name',
34
            'email',
35
            'sales' => array(
36
                'rootTag' => 'sales',
37
                'rowTag' => 'sale',
38
                'idColumn' => 'saleid',
39
                'elements' => array(
40
                    'saleid',
41
                    'timestamp',
42
                    'date' => '#Callbacks::getFirstWord()',
43
                    'time' => '#Callbacks::getSecondWord()',
44
                    'album' => array(
45
                        'rootTag' => '',
46
                        'rowTag' => 'album',
47
                        'idColumn' => 'albumid',
48
                        'elements' => array(
49
                            'albumid',
50
                            'title',
51
                            'published_year',
52
                            'comment',
53
                            'artist' => array(
54
                                'rootTag' => '',
55
                                'rowTag' => 'artist',
56
                                'idColumn' => 'artistid',
57
                                'elements' => array(
58
                                    'artistid',
59
                                    'name',
60
                                    'birth_year',
61
                                    'birth_place',
62
                                    'genre'
63
                                ) //artist elements
64
                            ) //artist array
65
                        ) //album elements
66
                    ) //album array
67
                ) //sales elements
68
            ) //sales array
69
        ) //root elements
70
    ) //root
71
); //getXML method call
72
 
73
$root = $dom->firstChild;
74
$root->setAttribute('date_generated', '2005-08-23T14:52:50');
75
 
76
header('Content-Type: application/xml');
77
 
78
$dom->formatOutput = true;
79
print $dom->saveXML();
80
 
81
require_once 'File.php';
82
$fp = new File();
83
$fp->write('case05.profile', $query2xml->getProfile(), FILE_MODE_WRITE);
84
 
85
class Callbacks
86
{
87
    function getFirstWord($record)
88
    {
89
        return substr($record['timestamp'], 0, strpos($record['timestamp'], ' '));
90
    }
91
 
92
    function getSecondWord($record)
93
    {
94
        return substr($record['timestamp'], strpos($record['timestamp'], ' ') + 1);
95
    }
96
}
97
?>