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

Class: XML_Query2XML

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

Class Overview


Create XML data from SQL queries.


Author(s):

Version:

  • Release: 1.7.2

Copyright:

  • 2006 Lukas Feiler

Methods


Inherited Variables

Inherited Methods


Class Details

[line 63]
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.



[ Top ]


Method Detail

clearProfile   [line 476]

void clearProfile( )

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

[ Top ]

disableDebugLog   [line 376]

void disableDebugLog( )

Disable the logging of debug messages
  • Access: public

[ Top ]

enableDebugLog   [line 364]

void enableDebugLog( mixed $log)

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

Parameters:

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

[ Top ]

factory   [line 225]

XML_Query2XML factory( mixed $backend)

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

Parameters:

mixed   $backend   —  An instance of PEAR DB, PEAR MDB2, ADOdb, PDO, Net_LDAP or a subclass of XML_Query2XML_Driver.

[ Top ]

getFlatXML   [line 519]

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.  <?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

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 ]

getGlobalOption   [line 332]

mixed getGlobalOption( string $option)

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

Parameters:

string   $option   —  The name of the option

[ Top ]

getProfile   [line 436]

string getProfile( )

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

[ Top ]

getRawProfile   [line 424]

array getRawProfile( )

Returns all raw profiling data.

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


[ Top ]

getXML   [line 565]

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 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

Parameters:

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).

[ Top ]

registerPrefix   [line 243]

void registerPrefix( string $prefix, string $className, [string $filePath = ''])

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

Parameters:

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.

[ Top ]

setGlobalOption   [line 294]

void setGlobalOption( string $option, mixed $value)

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

Parameters:

string   $option   —  The name of the option
mixed   $value   —  The option value

[ Top ]

startProfiling   [line 387]

void startProfiling( )

Start profiling.
  • Access: public

[ Top ]

stopProfiling   [line 406]

void stopProfiling( )

Stop profiling.
  • Access: public

[ Top ]

unregisterAllPrefixes   [line 273]

void unregisterAllPrefixes( )

Unregister all prefixes.
  • Access: public

[ Top ]

unregisterPrefix   [line 263]

void unregisterPrefix( string $prefix)

Unregister a prefix.
  • Access: public

Parameters:

string   $prefix   —  The prefix name.

[ Top ]


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