diff --git a/user_guide_src/source/database/utilities.rst b/user_guide_src/source/database/utilities.rst index 6bbc99b28ced..8a094cfff549 100644 --- a/user_guide_src/source/database/utilities.rst +++ b/user_guide_src/source/database/utilities.rst @@ -1,6 +1,6 @@ -######### -Utilities -######### +###################### +Database Utility Class +###################### The Database Utility Class contains methods that help you manage your database. @@ -8,18 +8,38 @@ The Database Utility Class contains methods that help you manage your database. :local: :depth: 2 -******************* -Get XML from Result -******************* +****************************** +Initializing the Utility Class +****************************** -getXMLFromResult() -================== +Load the Utility Class as follows: -This method returns the xml result from database result. You can do like this: +.. literalinclude:: utilities/002.php + :lines: 2- + +You can also pass another database group to the DB Utility loader, in case +the database you want to manage isn't the default one: + +.. literalinclude:: utilities/003.php + :lines: 2- + +In the above example, we're passing a database group name as the first +parameter. + +**************************** +Using the Database Utilities +**************************** + +Export a Query Result as an XML Document +======================================== + +Permits you to generate an XML file from a query result. The first +parameter expects a query result object, the second may contain an +optional array of config parameters. Example: .. literalinclude:: utilities/001.php -and it will get the following xml result:: +and it will get the following xml result when the ``mytable`` has columns ``id`` and ``name``:: @@ -27,3 +47,7 @@ and it will get the following xml result:: bar + +.. important:: This method will NOT write the XML file for you. It + simply creates the XML layout. If you need to write the file + use the :php:func:`write_file()` helper. diff --git a/user_guide_src/source/database/utilities/001.php b/user_guide_src/source/database/utilities/001.php index 41582ffca023..131222efc86b 100644 --- a/user_guide_src/source/database/utilities/001.php +++ b/user_guide_src/source/database/utilities/001.php @@ -1,13 +1,15 @@ query('SELECT * FROM mytable'); -$util = \CodeIgniter\Database\Config::utils(); +$config = [ + 'root' => 'root', + 'element' => 'element', + 'newline' => "\n", + 'tab' => "\t", +]; -echo $util->getXMLFromResult($model->get()); +echo $dbutil->getXMLFromResult($query, $config); diff --git a/user_guide_src/source/database/utilities/002.php b/user_guide_src/source/database/utilities/002.php new file mode 100644 index 000000000000..42bbbd63acc6 --- /dev/null +++ b/user_guide_src/source/database/utilities/002.php @@ -0,0 +1,3 @@ +