Skip to content

Commit c5cb69e

Browse files
authored
Merge pull request #8276 from kenjis/fix-docs-db-utils
docs: fix Database Utility Class `getXMLFromResult()`
2 parents 667cfd2 + b555ce2 commit c5cb69e

File tree

4 files changed

+50
-18
lines changed

4 files changed

+50
-18
lines changed
Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,53 @@
1-
#########
2-
Utilities
3-
#########
1+
######################
2+
Database Utility Class
3+
######################
44

55
The Database Utility Class contains methods that help you manage your database.
66

77
.. contents::
88
:local:
99
:depth: 2
1010

11-
*******************
12-
Get XML from Result
13-
*******************
11+
******************************
12+
Initializing the Utility Class
13+
******************************
1414

15-
getXMLFromResult()
16-
==================
15+
Load the Utility Class as follows:
1716

18-
This method returns the xml result from database result. You can do like this:
17+
.. literalinclude:: utilities/002.php
18+
:lines: 2-
19+
20+
You can also pass another database group to the DB Utility loader, in case
21+
the database you want to manage isn't the default one:
22+
23+
.. literalinclude:: utilities/003.php
24+
:lines: 2-
25+
26+
In the above example, we're passing a database group name as the first
27+
parameter.
28+
29+
****************************
30+
Using the Database Utilities
31+
****************************
32+
33+
Export a Query Result as an XML Document
34+
========================================
35+
36+
Permits you to generate an XML file from a query result. The first
37+
parameter expects a query result object, the second may contain an
38+
optional array of config parameters. Example:
1939

2040
.. literalinclude:: utilities/001.php
2141

22-
and it will get the following xml result::
42+
and it will get the following xml result when the ``mytable`` has columns ``id`` and ``name``::
2343

2444
<root>
2545
<element>
2646
<id>1</id>
2747
<name>bar</name>
2848
</element>
2949
</root>
50+
51+
.. important:: This method will NOT write the XML file for you. It
52+
simply creates the XML layout. If you need to write the file
53+
use the :php:func:`write_file()` helper.
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3-
class MyModel extends \CodeIgniter\Model
4-
{
5-
protected $table = 'foo';
6-
protected $primaryKey = 'id';
7-
}
3+
$db = db_connect();
4+
$dbutil = \Config\Database::utils();
85

9-
$model = new MyModel();
6+
$query = $db->query('SELECT * FROM mytable');
107

11-
$util = \CodeIgniter\Database\Config::utils();
8+
$config = [
9+
'root' => 'root',
10+
'element' => 'element',
11+
'newline' => "\n",
12+
'tab' => "\t",
13+
];
1214

13-
echo $util->getXMLFromResult($model->get());
15+
echo $dbutil->getXMLFromResult($query, $config);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$dbutil = \Config\Database::utils();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$dbutil = \Config\Database::utils('group_name');

0 commit comments

Comments
 (0)