File tree Expand file tree Collapse file tree 2 files changed +21
-15
lines changed
user_guide_src/source/database Expand file tree Collapse file tree 2 files changed +21
-15
lines changed Original file line number Diff line number Diff line change @@ -8,22 +8,26 @@ The Database Utility Class contains methods that help you manage your database.
8
8
:local:
9
9
:depth: 2
10
10
11
- *******************
12
- Get XML from Result
13
- *******************
14
11
15
- getXMLFromResult()
16
- ==================
12
+ Export a Query Result as an XML Document
13
+ ========================================
17
14
18
- This method returns the xml result from database result. You can do like this:
15
+ Permits you to generate an XML file from a query result. The first
16
+ parameter expects a query result object, the second may contain an
17
+ optional array of config parameters. Example:
19
18
20
19
.. literalinclude :: utilities/001.php
21
20
22
- and it will get the following xml result::
21
+ and it will get the following xml result when the `` mytable `` has columns `` id `` and `` name `` ::
23
22
24
23
<root>
25
24
<element>
26
25
<id>1</id>
27
26
<name>bar</name>
28
27
</element>
29
28
</root>
29
+
30
+ .. important :: This method will NOT write the XML file for you. It
31
+ simply creates the XML layout. If you need to write the file
32
+ use the :php:func: `write_file() ` helper.
33
+
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- class MyModel extends \CodeIgniter \Model
4
- {
5
- protected $ table = 'foo ' ;
6
- protected $ primaryKey = 'id ' ;
7
- }
3
+ $ db = db_connect ();
4
+ $ dbutil = \CodeIgniter \Database \Config::utils ();
8
5
9
- $ model = new MyModel ( );
6
+ $ query = $ db -> query ( ' SELECT * FROM mytable ' );
10
7
11
- $ util = \CodeIgniter \Database \Config::utils ();
8
+ $ config = [
9
+ 'root ' => 'root ' ,
10
+ 'element ' => 'element ' ,
11
+ 'newline ' => "\n" ,
12
+ 'tab ' => "\t" ,
13
+ ];
12
14
13
- echo $ util ->getXMLFromResult ($ model -> get () );
15
+ echo $ dbutil ->getXMLFromResult ($ query , $ config );
You can’t perform that action at this time.
0 commit comments