diff --git a/system/Database/BaseUtils.php b/system/Database/BaseUtils.php index cab813d6c10d..50f3021c3dfb 100644 --- a/system/Database/BaseUtils.php +++ b/system/Database/BaseUtils.php @@ -301,7 +301,7 @@ public function getXMLFromResult(ResultInterface $query, $params = []) extract($params); // Load the xml helper -// get_instance()->load->helper('xml'); + helper('xml'); // Generate the result $xml = '<' . $root . '>' . $newline; while ($row = $query->getUnbufferedRow()) diff --git a/system/Database/MySQLi/Utils.php b/system/Database/MySQLi/Utils.php new file mode 100644 index 000000000000..af0ca54da224 --- /dev/null +++ b/system/Database/MySQLi/Utils.php @@ -0,0 +1,74 @@ +', '"', "'", '-'], + ['&', '<', '>', '"', ''', '-'], + $str + ); + + // Decode the temp markers back to entities + $str = preg_replace('/'.$temp.'(\d+);/', '&#\\1;', $str); + + if ($protect_all === TRUE) + { + return preg_replace('/'.$temp.'(\w+);/', '&\\1;', $str); + } + + return $str; + } +} \ No newline at end of file diff --git a/user_guide_src/source/database/index.rst b/user_guide_src/source/database/index.rst index 15b15fae92a8..62002afd00a8 100644 --- a/user_guide_src/source/database/index.rst +++ b/user_guide_src/source/database/index.rst @@ -20,3 +20,4 @@ patterns. The database functions offer clear, simple syntax. Getting MetaData Custom Function Calls Database Events + Database Utilities \ No newline at end of file diff --git a/user_guide_src/source/database/utilities.rst b/user_guide_src/source/database/utilities.rst new file mode 100644 index 000000000000..dfaa51864510 --- /dev/null +++ b/user_guide_src/source/database/utilities.rst @@ -0,0 +1,37 @@ +######################## +Utilities +######################## + +The Database Utility Class contains methods that help you manage your database. + +.. contents:: + :local: + :depth: 2 + +******************* +Get XML FROM Result +******************* + +**getXMLFromResult()** + +This method returns the xml result from database result. You can do like this:: + + $model = new class extends \CodeIgniter\Model { + protected $table = 'foo'; + protected $primaryKey = 'id'; + }; + $db = \Closure::bind(function ($model) { + return $model->db; + }, null, $model)($model); + + $util = (new \CodeIgniter\Database\Database())->loadUtils($db); + echo $util->getXMLFromResult($model->get()); + +and it will get the following xml result:: + + + + 1 + bar + +