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

Class: XML_sql2xml

Source Location: /XML_sql2xml-0.3.3/sql2xml.php

Class Overview


This class takes a PEAR::DB-Result Object, a sql-query-string or an array and returns a xml-representation of it.


Author(s):

Version:

  • $Id: sql2xml.php,v 1.16 2008/03/24 00:11:47 ifeghali Exp $

Variables

Methods


Child classes:

XML_sql2xml_ext
This class shows with an example, how the base sql2xml-class could be extended.

Inherited Variables

Inherited Methods


Class Details

[line 54]
This class takes a PEAR::DB-Result Object, a sql-query-string or an array and returns a xml-representation of it.

TODO -encoding etc, options for header -ERROR CHECKING

Usage example

include_once ("DB.php"); include_once("XML/sql2xml.php"); $db = DB::connect("mysql://root@localhost/xmltest"); $sql2xml = new xml_sql2xml(); //the next one is only needed, if you need others than the default $sql2xml->setEncoding("ISO-8859-1","UTF-8"); $result = $db->query("select * from bands"); $xmlstring = $sql2xml->getXML($result);

or

include_once ("DB.php"); include_once("XML/sql2xml.php"); $sql2xml = new xml_sql2xml("mysql://root@localhost/xmltest"); $sql2xml->Add("select * from bands"); $xmlstring = $sql2xml->getXML();

More documentation and a tutorial/how-to can be found at http://php.chregu.tv/sql2xml

  • Author: Christian Stocker <chregu@bitflux.ch>
  • Version: $Id: sql2xml.php,v 1.16 2008/03/24 00:11:47 ifeghali Exp $


[ Top ]


Class Variables

$encoding_from =  'ISO-8859-1'

[line 160]

the encoding type, the input from the db has

Type:   mixed


[ Top ]

$encoding_to =  'UTF-8'

[line 166]

the encoding type, the output in the xml should have

(note that domxml at the moment only support UTF-8, or at least it looks like)


Type:   mixed


[ Top ]

$nested =  True

[line 67]

If joined-tables should be output nested.

Means, if you have joined two or more queries, the later specified tables will be nested within the result of the former table. Works at the moment only with mysql automagically. For other RDBMS you have to provide your table-relations by hand (see user_tableinfo)

  • See: $user_tableinfo, doSql2Xml(), doArray2Xml();

Type:   boolean


[ Top ]

$tagname =  'tagname'

[line 168]


Type:   mixed


[ Top ]

$tagNameResult =  "result"

[line 75]

Name of the tag element for resultsets
  • See: insertNewResult()

Type:   string


[ Top ]

$tagNameRow =  "row"

[line 83]

Name of the tag element for rows
  • See: insertNewRow()

Type:   string


[ Top ]

$user_options = array()

[line 102]

Options to be used in extended Classes (for example in sql2xml_ext).

They are passed with SetOptions as an array (arrary("user_options" = array()); and can then be accessed with $this->user_options["bla"] from your extended classes for additional features. This array is not use in this base class, it's only for passing easy parameters to extended classes.


Type:   array


[ Top ]



Method Detail

XML_sql2xml (Constructor)   [line 188]

XML_sql2xml XML_sql2xml( [mixed $dsn = Null], [string $root = 'root'])

Constructor The Constructor can take a Pear::DB "data source name" (eg.

"mysql://user:passwd@localhost/dbname") and will then connect to the DB, or a PEAR::DB object link, if you already connected the db before. a pear::db-resultset or as an array. providing sql-strings will not work. the $root param is used, if you want to provide another name for your root-tag than "root". if you give an empty string (""), there will be no root element created here, but only when you add a resultset/array/sql-string. And the first tag of this result is used as the root tag.

  • Access: public

Parameters:

mixed   $dsn     PEAR::DB "data source name" or object DB object
string   $root     the name of the xml-doc root element.

[ Top ]

add   [line 233]

void add( string $resultset, [mixed $params = null])

General method for adding new resultsets to the xml-object

Give a sql-query-string, a pear::db_result object or an array as input parameter, and the method calls the appropriate method for this input and adds this to $this->xmldoc


Parameters:

string   $resultset     sql-string, or object db_result, or array
mixed   $params     additional parameters for the following functions

[ Top ]

addArray   [line 336]

void addArray( array $array, [ $prefix = 'index_'])

Adds an aditional resultset generated from an Array to $this->xmldoc TODO: more explanation, how arrays are transferred
  • See: doArray2Xml()
  • Access: public

Parameters:

array   $array     multidimensional array.
   $prefix     

[ Top ]

addResult   [line 291]

void addResult( Object $result)

Adds an additional pear::db_result resultset to $this->xmldoc
  • See: doSql2Xml()
  • Access: public

Parameters:

Object   $result     db_result result from a DB-query

[ Top ]

addSql   [line 304]

void addSql( string $sql)

Adds an aditional resultset generated from an sql-statement to $this->xmldoc
  • See: doSql2Xml()
  • Access: public

Parameters:

string   $sql     sql a string containing an sql-statement.

[ Top ]

addXmlFile   [line 264]

void addXmlFile( string $file, [mixed $xpath = null])

Adds the content of a xml-file to $this->xmldoc, on the same level as a normal resultset (mostly just below <root>)
  • See: doXmlString2Xml()
  • Access: public

Parameters:

string   $file     filename
mixed   $xpath     xpath either a string with the xpath expression or an array with "xpath"=>xpath expression and "root"=tag/subtag/etc, which are the tags to be inserted before the result

[ Top ]

addXmlString   [line 279]

void addXmlString( string $string, [mixed $xpath = null])

Adds the content of a xml-string to $this->xmldoc, on the same level as a normal resultset (mostly just below <root>)
  • See: doXmlString2Xml()
  • Access: public

Parameters:

string   $string     xml
mixed   $xpath     xpath either a string with the xpath expression or an array with "xpath"=>xpath expression and "root"=tag/subtag/etc, which are the tags to be inserted before the result

[ Top ]

getXML   [line 389]

string getXML( [mixed $result = null])

Returns an xml-string with a xml-representation of the resultsets.

The resultset can be directly provided here, or if you need more than one in your xml, then you have to provide each of them with add() before you call getXML, but the last one can also be provided here.

  • Return: xml
  • Access: public

Parameters:

mixed   $result     result Object from a DB-query

[ Top ]

getXMLObject   [line 406]

Object getXMLObject( [mixed $result = null])

Returns an xml DomDocument Object with a xml-representation of the resultsets.

The resultset can be directly provided here, or if you need more than one in your xml, then you have to provide each of them with add() before you call getXMLObject, but the last one can also be provided here.

  • Return: DomDocument
  • Access: public

Parameters:

mixed   $result     result Object from a DB-query

[ Top ]

getXpathChildValues   [line 792]

array getXpathChildValues( string $expr)

get the values as an array from the childtags from the first match of the xpath expression
  • Return: with key->value of subtags
  • Access: public

Parameters:

string   $expr     xpath expression

[ Top ]

getXpathValue   [line 770]

mixed getXpathValue( string $expr)

returns the content of the first match of the xpath expression
  • Return: content of the evaluated xpath expression
  • Access: public

Parameters:

string   $expr     xpath expression

[ Top ]

prepareArray   [line 356]

void prepareArray( array $array, [prefix $prefix = 'index_'])

Makes sure the given array has no integer indices
  • See: doArray()
  • Access: public

Parameters:

array   $array     multidimensional array.
prefix   $prefix     string to prefix integer indices

[ Top ]

setEncoding   [line 745]

void setEncoding( [string $encoding_from = 'ISO-8859-1'], [string $encoding_to = 'UTF-8'])

sets the encoding for the db2xml transformation
  • Access: public

Parameters:

string   $encoding_from     encoding to transform from
string   $encoding_to     encoding to transform to

[ Top ]

setOptions   [line 569]

void setOptions( array $options, [boolean $delete = false])

This method sets the options for the class One can only set variables, which are defined at the top of of this class.

Parameters:

array   $options     options to be passed to the class
boolean   $delete     if the old suboptions should be deleted

[ Top ]

SetParentTables   [line 755]

void SetParentTables( array $parentTables)

  • Access: public

Parameters:

array   $parentTables     parent to child relation

[ Top ]


Documentation generated on Sun, 23 Mar 2008 21:00:04 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.