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

Class: XML_Query2XML

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

Class Overview


Create XML data from SQL queries.


Author(s):

Version:

  • Release: 1.1.0

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, PEAR MDB2 or ADOdb is also required. 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 DOM XML extension.

A typical usage of XML_Query2XML looks like this:

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

Please read the XML_Query2XML.pkg for detailed usage examples and more documentation.

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


[ Top ]


Method Detail

clearProfile   [line 418]

void clearProfile( )

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

[ Top ]

disableDebugLog   [line 314]

void disableDebugLog( )

Disable the logging of debug messages
  • Access: public

[ Top ]

enableDebugLog   [line 305]

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(MDB2::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.

  • 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 224]

XML_Query2XML factory( mixed $db)

Factory method.

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

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

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

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

Parameters:

mixed   $db   —  An instance of PEAR DB, PEAR MDB2 or ADOdb.

[ Top ]

getFlatXML   [line 457]

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(MDB2::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_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 278]

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

string getProfile( )

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

[ Top ]

getRawProfile   [line 354]

array getRawProfile( )

Returns all raw profiling data.

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


[ Top ]

getXML   [line 498]

DomDocument getXML( $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 XML_Query2XML.pkg 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:

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

[ Top ]

setGlobalOption   [line 242]

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

void startProfiling( )

Start profiling.
  • Access: public

[ Top ]

stopProfiling   [line 338]

void stopProfiling( )

Stop profiling.
  • Access: public

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:56:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.