XML_Query2XML
[ class tree: XML_Query2XML ] [ index: XML_Query2XML ] [ all elements ]

Source for file case05.php

Documentation is available at case05.php

  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. $dom $query2xml->getXML(
  6.     "SELECT
  7.          *
  8.      FROM
  9.          customer c
  10.          LEFT JOIN sale s ON c.customerid = s.customer_id
  11.          LEFT JOIN album al ON s.album_id = al.albumid
  12.          LEFT JOIN artist ar ON al.artist_id = ar.artistid
  13.      ORDER BY
  14.          c.customerid,
  15.          s.saleid,
  16.          al.albumid,
  17.          ar.artistid",
  18.     array(
  19.         'rootTag' => 'music_store',
  20.         'rowTag' => 'customer',
  21.         'idColumn' => 'customerid',
  22.         'elements' => array(
  23.             'customerid',
  24.             'first_name',
  25.             'last_name',
  26.             'email',
  27.             'sales' => array(
  28.                 'rootTag' => 'sales',
  29.                 'rowTag' => 'sale',
  30.                 'idColumn' => 'saleid',
  31.                 'elements' => array(
  32.                     'saleid',
  33.                     'timestamp',
  34.                     'date' => '#Callbacks::getFirstWord()',
  35.                     'time' => '#Callbacks::getSecondWord()',
  36.                     'album' => array(
  37.                         'rootTag' => '',
  38.                         'rowTag' => 'album',
  39.                         'idColumn' => 'albumid',
  40.                         'elements' => array(
  41.                             'albumid',
  42.                             'title',
  43.                             'published_year',
  44.                             'comment',
  45.                             'artist' => array(
  46.                                 'rootTag' => '',
  47.                                 'rowTag' => 'artist',
  48.                                 'idColumn' => 'artistid',
  49.                                 'elements' => array(
  50.                                     'artistid',
  51.                                     'name',
  52.                                     'birth_year',
  53.                                     'birth_place',
  54.                                     'genre'
  55.                                 //artist elements
  56.                             //artist array
  57.                         //album elements
  58.                     //album array
  59.                 //sales elements
  60.             //sales array
  61.         //root elements
  62.     //root
  63. )//getXML method call
  64.  
  65. $root $dom->firstChild;
  66. $root->setAttribute('date_generated''2005-08-23T14:52:50');
  67.  
  68. header('Content-Type: application/xml');
  69.  
  70. $dom->formatOutput = true;
  71. print $dom->saveXML();
  72.  
  73. class Callbacks
  74. {
  75.     function getFirstWord($record)
  76.     {
  77.         return substr($record['timestamp']0strpos($record['timestamp']' '));
  78.     }
  79.     
  80.     function getSecondWord($record)
  81.     {
  82.         return substr($record['timestamp']strpos($record['timestamp']' '+ 1);
  83.     }
  84. }
  85. ?>

Documentation generated on Mon, 11 Mar 2019 15:43:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.