PluginProbe
SEO Redirection Plugin – 301 Redirect Manager / 8.4
SEO Redirection Plugin – 301 Redirect Manager v8.4
9.19 trunk 4.17 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.1 9.10 9.11 9.12 All 39 releases
seo-redirection / custom / export / xml.php

xml.php in SEO Redirection Plugin – 301 Redirect Manager 8.4, at custom/export/xml.php

57 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // setting up PDO
4 $dbLocation = 'mysql:dbname=db001;host=localhost';
5 $dbUser = 'user';
6 $dbPass = 'password';
7 $db = new PDO($dbLocation, $dbUser, $dbPass);
8
9 // prepare all queries...
10 $dbArtists = $db->prepare("SELECT * FROM artist");
11 $dbAlbums = $db->prepare("SELECT * FROM album WHERE artist_ID=:artist_id");
12 $dbSongs = $db->prepare("SELECT * FROM song WHERE album_ID=:album_id");
13
14 // fetch all artists
15 $dbArtists->execute();
16 $artists=$dbArtists->fetchAll(PDO::FETCH_ASSOC);
17
18
19 $x=new XMLWriter();
20 $x->openMemory();
21 $x->startDocument('1.0','UTF-8');
22 $x->startElement('music');
23
24 foreach ($artists as $artist) {
25
26 $x->startElement('artist');
27 $x->writeAttribute('name',$artist['artist']);
28
29 // fetch all albums of this artist
30 $dbAlbums->execute(array(':artist_id' => $artist['artist_id']));
31 $albums = $dbAlbums->fetchAll(PDO::FETCH_ASSOC);
32
33 foreach ($albums as $album) {
34
35 $x->startElement('album');
36 $x->writeAttribute('name',$album['album']);
37
38 // fetch all songs from this album
39 $dbSongs->execute(array(':album_id' => $album['album_id']));
40 $songs = $dbSongs->fetchAll(PDO::FETCH_ASSOC);
41
42 foreach ($songs as $song) {
43
44 $x->startElement('song');
45 $x->text($song['song']);
46 $x->endElement(); // song
47 } // foreach $songs
48
49 $x->endElement(); // album
50 } // foreach $albums
51
52 $x->endElement(); // artist
53 } // foreach $artists
54
55 $x->endElement(); // music
56 $x->endDocument();
57 $xml = $x->outputMemory();