1 Select
Shikiryu edited this page 2019-10-21 09:45:00 +02:00

We offered you 5 ways to Select into the XMLDB:

You can find the different return value possible here.

Select table

Syntax: public function selectTable($name, $format = 'node')

Example:

$xmldb = new XMLDB('db.xml');
$xmldb->selectTable('table1');

By default, the function returns a node (a DOMDocument NodeList)

this will select the table (with the table configuration)

Select everything from a table

Syntax: public function selectAllFromTable($name, $format = 'node')

Example:

$xmldb = new XMLDB('db.xml');
$xmldb->selectAllFromTable('table1', 'count');

This will return the number of items inside table1. By default, it'll return a node.

Select with primary key

Syntax: public function selectFromPK($table, $pk, $format = "array")

Example:

$xmldb = new XMLDB('db.xml');
$xmldb->selectFromPK('table1', 'weather');

By default, the function returns an array

Select with other attributes

Syntax: public function selectFromAttribute($table, $attributes, $format = 'array')

Example:

$xmldb = new XMLDB('db.xml');
$xmldb->selectFromAttribute('table1', array('id'=>'weather'));

By default, the function returns an array

You can notice that this example returns the same thing as with PK if your pk stays with "id" because the primary key is an attribute.

Select with children

Syntax: public function selectFromChildren($table, $childs, $format = 'array')

Example:

$xmldb = new XMLDB('db.xml');
$xmldb->selectFromChildren('table1',array('visibility'=>'true'));

By default, the function returns an array. Here, it will select all items having a child like this : <visibility>true</visibility>