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.
88 :local:
99 :depth: 2
1010
11- *******************
12- Get XML from Result
13- *******************
1411
15- getXMLFromResult()
16- ==================
12+ Export a Query Result as an XML Document
13+ ========================================
1714
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:
1918
2019.. literalinclude :: utilities/001.php
2120
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 `` ::
2322
2423 <root>
2524 <element>
2625 <id>1</id>
2726 <name>bar</name>
2827 </element>
2928 </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 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 = \CodeIgniter \Database \Config::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 );
You can’t perform that action at this time.
0 commit comments