Shikiryu 2019-10-21 09:45:00 +02:00
parent d6f245b26a
commit f3130bbe1d

72
Select.md Normal file

@ -0,0 +1,72 @@
We offered you 5 ways to `Select` into the XMLDB:
*You can find the different [return value](Return-value) possible here.*
## Select table
*Syntax:* `public function selectTable($name, $format = 'node')`
*Example:*
```php
$xmldb = new XMLDB('db.xml');
$xmldb->selectTable('table1');
```
By default, the function returns a _node_ ([a DOMDocument NodeList](http://www.php.net/manual/fr/class.domnodelist.php))
this will select the table (with the table configuration)
## Select everything from a table
*Syntax:* `public function selectAllFromTable($name, $format = 'node')`
*Example:*
```php
$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:*
```php
$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:*
```php
$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:*
```php
$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>`