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

Class: XML_Query2XML

Source Location: /XML_Query2XML-0.6.0/XML/Query2XML.php

Class Overview


Create XML data from SQL queries.


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • Empowered Media 2006

Methods


Inherited Variables

Inherited Methods


Class Details

[line 64]
Create XML data from SQL queries.

XML_Query2XML heavily uses exceptions and therefore requires PHP5. PEAR DB or PEAR MDB2 is also required. The two most important public methods this class provides are:

Transforms your SQL query into flat XML data.

Very powerful and flexible method that can produce whatever XML data you want. It was specifically written to also handle LEFT JOINS.

They both return an instance of the class DomDocument provided by PHP5's DOM XML extension.

A typical usage of XML_Query2XML looks like this:


1 require_once('XML/Query2XML.php');
2 $query2xml = new XML_Query2XML(DB::connect($dsn));
3 $dom = $query2xml->getXML($sql, $options);
4 header('Content-Type: application/xml');
5 print $dom->saveXML();

Please read the for detailed usage examples and more documentation.

  • Todo: $options['idColumn'] should also accept multiple columns in an array
  • Copyright: Empowered Media 2006
  • Version: Release: @package_version@
  • Author: Lukas Feiler <mailto:lukas.feiler@lukasfeiler.com>


[ Top ]


Method Detail

clearProfile   [line 313]

void clearProfile( )

Calls XML_Query2XML::stopProfiling() and then clears the profiling data by resetting a private property.

[ Top ]

disableDebugLog   [line 214]

void disableDebugLog( )

Disable the logging of debug messages

[ Top ]

enableDebugLog   [line 206]

void enableDebugLog( mixed $log)

Enable the logging of debug messages.

This will include all queries sent to the database. Example:


1 require_once('Log.php');
2 require_once('XML/Query2XML.php');
3 $query2xml = new XML_Query2XML(DB::connect($dsn));
4 $debugLogger = Log::factory('file', 'out.log', 'XML_Query2XML');
5 $query2xml->enableDebugLog($debugLogger);
Please see http://pear.php.net/package/Log for details on PEAR Log.


Parameters:

mixed   $log     Most likely an instance of PEAR::Log but any object that provides a method named 'log' is accepted.

[ Top ]

factory   [line 186]

XML_Query2XML factory( mixed $db)

Factory method.

As first argument pass an instance of PEAR DB or PEAR MDB2:


1 require_once('XML/Query2XML.php');
2 require_once('DB.php');
3 $query2xml = XML_Query2XML::factory(
4 DB::connect('mysql://root@localhost/Query2XML_Tests')
5 );


1 require_once('XML/Query2XML.php');
2 require_once('MDB2.php');
3 $query2xml = XML_Query2XML::factory(
4 MDB2::factory('mysql://root@localhost/Query2XML_Tests')
5 );

  • Return: A new instance of XML_Query2XML
  • Throws: XML_Query2XML_ConfigException If $db is not an instance of a child class of DB_common or MDB2_Driver_Common.
  • Throws: XML_Query2XML_DBException If $db already is a PEAR error.

Parameters:

mixed   $db     An instance of PEAR DB or PEAR MDB2

[ Top ]

getFlatXML   [line 351]

DomDocument getFlatXML( string $sql, [string $rootTagName = 'root'], [string $rowTagName = 'row'])

Transforms the data retrieved by a single SQL query into flat XML data.

This method will return a new instance of DomDocument. The column names will be used as element names.

Example:


1 require_once('XML/Query2XML.php');
2 $query2xml = XML_Query2XML::factory(DB::connect($dsn));
3 $dom = $query2xml->getFlatXML(
4 'SELECT * FROM artist',
5 'music_library',
6 'artist'
7 );

  • Return: A new instance of DomDocument.
  • Throws: XML_Query2XML_XMLException If an XML error occurrs - most likely $rootTagName or $rowTagName is not a valid element name.
  • Throws: XML_Query2XML_DBException If a database error occurrs.
  • Throws: XML_Query2XML_Exception This is the base class for the exception types XML_Query2XML_DBException and XML_Query2XML_XMLException. By catching XML_Query2XML_Exception you can catch all exceptions this method will ever throw.

Parameters:

string   $sql     The query string.
string   $rootTagName     The name of the root tag; this argument is optional (default: 'root').
string   $rowTagName     The name of the tag used for each row; this argument is optional (default: 'row').

[ Top ]

getProfile   [line 260]

string getProfile( )

Returns the profile as a single multi line string.
  • Return: The profiling data.

[ Top ]

getRawProfile   [line 251]

array getRawProfile( )

Returns all raw profiling data.

In 99.9% of all cases you will want to use getProfile()


[ Top ]

getXML   [line 386]

DomDocument getXML( mixed $sql, array $options)

Transforms your SQL data retrieved by one or more queries into complex and highly configurable XML data.

This method will return a new instance of DomDocument. Please see the for details.

  • Return: The XML data as a new instance of DomDocument.
  • Throws: XML_Query2XML_ConfigException If some configuration options passed as second argument are invalid or missing.
  • Throws: XML_Query2XML_XMLException If an XML error occurrs - most likely an invalid XML element name.
  • Throws: XML_Query2XML_DBException If a database error occurrs.
  • Throws: XML_Query2XML_Exception This is the base class for the exception types XML_Query2XML_DBException, XML_Query2XML_XMLException and XML_Query2XML_ConfigException. By catching XML_Query2XML_Exception you can catch all exceptions this method will ever throw.

Parameters:

array   $options     Options for the creation of the XML data stored in an associative, potentially mutli-dimensional array (please see the tutorial).

[ Top ]

startProfiling   [line 221]

void startProfiling( )

Start profiling.

[ Top ]

stopProfiling   [line 236]

void stopProfiling( )

Stop profiling.

[ Top ]


Documentation generated on Sun, 23 Apr 2006 11:33:24 -0400 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.