Utilities

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

Get XML FROM Result

getXMLFromResult()

This method returns the xml result from database result. You can do like this:

  1. $model = new class extends \CodeIgniter\Model {
  2. protected $table = 'foo';
  3. protected $primaryKey = 'id';
  4. };
  5. $db = \Closure::bind(function ($model) {
  6. return $model->db;
  7. }, null, $model)($model);
  8.  
  9. $util = (new \CodeIgniter\Database\Database())->loadUtils($db);
  10. echo $util->getXMLFromResult($model->get());

and it will get the following xml result:

  1. <root>
  2. <element>
  3. <id>1</id>
  4. <name>bar</name>
  5. </element>
  6. </root>