Class XML_Query2XML

Description

Create XML data from SQL queries.

XML_Query2XML heavily uses exceptions and therefore requires PHP5. Additionally one of the following database abstraction layers is required: PDO (compiled-in by default since PHP 5.1), PEAR DB, PEAR MDB2, ADOdb.

The two most important public methods this class provides are:

XML_Query2XML::getFlatXML() Transforms your SQL query into flat XML data.

XML_Query2XML::getXML() 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 built-in DOM API.

A typical usage of XML_Query2XML looks like this:

  1.  <?php
  2.  require_once 'XML/Query2XML.php';
  3.  $query2xml XML_Query2XML::factory(MDB2::factory($dsn));
  4.  $dom $query2xml->getXML($sql$options);
  5.  header('Content-Type: application/xml');
  6.  print $dom->saveXML();
  7.  ?>

Please read the tutorial for detailed usage examples and more documentation.

Located in /Query2XML.php (line 63)


	
			
Method Summary
static XML_Query2XML factory (mixed $backend)
void clearProfile ()
void disableDebugLog ()
void enableDebugLog (mixed $log)
DOMDocument getFlatXML (string $sql, [string $rootTagName = 'root'], [string $rowTagName = 'row'])
mixed getGlobalOption (string $option)
string getProfile ()
array getRawProfile ()
DOMDocument getXML (mixed $sql, array $options)
void registerPrefix (string $prefix, string $className, [string $filePath = ''])
void setGlobalOption (string $option, mixed $value)
void startProfiling ()
void stopProfiling ()
void unregisterPrefix (string $prefix)
Methods
static factory (line 225)

Factory method.

As first argument pass an instance of PDO, PEAR DB, PEAR MDB2, ADOdb, Net_LDAP or an instance of any class that extends XML_Query2XML_Driver:

  1.  <?php
  2.  require_once 'XML/Query2XML.php';
  3.  $query2xml XML_Query2XML::factory(
  4.    new PDO('mysql://root@localhost/Query2XML_Tests')
  5.  );
  6.  ?>

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

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

  1.  <?php
  2.  require_once 'XML/Query2XML.php';
  3.  require_once 'adodb/adodb.inc.php';
  4.  $adodb ADONewConnection('mysql');
  5.  $adodb->Connect('localhost''root''''Query2XML_Tests');
  6.  $query2xml XML_Query2XML::factory($adodb);
  7.  ?>

  • return: A new instance of XML_Query2XML
  • throws: XML_Query2XML_DriverException If $backend already is a PEAR_Error.
  • throws: XML_Query2XML_ConfigException If $backend is not an instance of a child class of DB_common, MDB2_Driver_Common, ADOConnection PDO, Net_LDAP or XML_Query2XML_Driver.
  • access: public
static XML_Query2XML factory (mixed $backend)
  • mixed $backend: An instance of PEAR DB, PEAR MDB2, ADOdb, PDO, Net_LDAP or a subclass of XML_Query2XML_Driver.
clearProfile (line 476)

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

  • access: public
void clearProfile ()
disableDebugLog (line 376)

Disable the logging of debug messages

  • access: public
void disableDebugLog ()
enableDebugLog (line 364)

Enable the logging of debug messages.

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

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

  • access: public
void enableDebugLog (mixed $log)
  • mixed $log: Most likely an instance of PEAR Log but any object that provides a method named 'log' is accepted.
getFlatXML (line 519)

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.  <?php
  2.  require_once 'XML/Query2XML.php';
  3.  $query2xml XML_Query2XML::factory(MDB2::connect($dsn));
  4.  $dom $query2xml->getFlatXML(
  5.    'SELECT * FROM artist',
  6.    'music_library',
  7.    'artist'
  8.  );
  9.  ?>

  • return: A new instance of DOMDocument.
  • 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.
  • throws: XML_Query2XML_DBException If a database error occurrs.
  • throws: XML_Query2XML_XMLException If an XML error occurrs - most likely $rootTagName or $rowTagName is not a valid element name.
  • access: public
DOMDocument getFlatXML (string $sql, [string $rootTagName = 'root'], [string $rowTagName = 'row'])
  • 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').
getGlobalOption (line 332)

Returns the current value for a global option.

See XML_Query2XML::setGlobalOption() for a list of available options.

  • return: The option's value
  • throws: XML_Query2XML_ConfigException If the option does not exist
  • access: public
mixed getGlobalOption (string $option)
  • string $option: The name of the option
getProfile (line 436)

Returns the profile as a single multi line string.

  • return: The profiling data.
  • access: public
string getProfile ()
getRawProfile (line 424)

Returns all raw profiling data.

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

array getRawProfile ()
getXML (line 565)

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 tutorial for details.

  • return: The XML data as a new instance of DOMDocument.
  • 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.
  • throws: XML_Query2XML_ConfigException If some configuration options passed as second argument are invalid or missing.
  • throws: XML_Query2XML_DBException If a database error occurrs.
  • throws: XML_Query2XML_XMLException If an XML error occurrs - most likely an invalid XML element name.
  • access: public
DOMDocument getXML (mixed $sql, array $options)
  • mixed $sql: A string an array or the boolean value false.
  • array $options: Options for the creation of the XML data stored in an associative, potentially mutli-dimensional array (please see the tutorial).
registerPrefix (line 243)

Register a prefix that can be used in all value specifications.

  • throws: XML_Query2XML_ConfigException Thrown if $prefix is not a string or has a length other than 1.
  • access: public
void registerPrefix (string $prefix, string $className, [string $filePath = ''])
  • string $prefix: The prefix name. This must be a single chracter.
  • string $className: The name of the Data Class. This class has to extend XML_Query2XML_Data.
  • string $filePath: The path to the file that contains the Command class. This argument is optional.
setGlobalOption (line 294)

Set a global option.

Currently the following global options are available:

hidden_container_prefix: The prefix to use for container elements that are to be removed before the DOMDocument before it is returned by XML_Query2XML::getXML(). This has to be a non-empty string. The default value is '__'.

  • throws: XML_Query2XML_ConfigException If the configuration option does not exist or if the value is invalid for that option
  • access: public
void setGlobalOption (string $option, mixed $value)
  • string $option: The name of the option
  • mixed $value: The option value
startProfiling (line 387)

Start profiling.

  • access: public
void startProfiling ()
stopProfiling (line 406)

Stop profiling.

  • access: public
void stopProfiling ()
unregisterAllPrefixes (line 273)

Unregister all prefixes.

  • access: public
void unregisterAllPrefixes ()
unregisterPrefix (line 263)

Unregister a prefix.

  • access: public
void unregisterPrefix (string $prefix)
  • string $prefix: The prefix name.

Documentation generated on Sun, 03 Apr 2011 13:13:11 +0200 by phpDocumentor 1.4.1