diff options
-rw-r--r-- | system/database/DB_result.php | 13 | ||||
-rw-r--r-- | user_guide_src/source/changelog.rst | 1 | ||||
-rw-r--r-- | user_guide_src/source/database/results.rst | 20 |
3 files changed, 34 insertions, 0 deletions
diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 196febe2c..25b4fb911 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -371,6 +371,19 @@ class CI_DB_result { // -------------------------------------------------------------------- /** + * Returns an unbuffered row and move pointer to next row + * + * @return mixed either a result object or array + */ + public function unbuffered_row($type = 'object') + { + return ($type !== 'array') ? $this->_fetch_object() : $this->_fetch_assoc(); + + } + + // -------------------------------------------------------------------- + + /** * The following functions are normally overloaded by the identically named * methods in the platform-specific driver -- except when query caching * is used. When caching is enabled we do not load the other driver. diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 6192fecfd..45e6ebc07 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -102,6 +102,7 @@ Release Date: Not Released - Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge <database/forge>`. - Added MSSQL, SQLSRV support for optimize_table() in :doc:`Database Utility <database/utilities>`. - Improved CUBRID support for list_databases() in :doc:`Database Utility <database/utilities>` (until now only the currently used database was returned). + - Added unbuffered_row() function for getting a row without prefetching whole result (consume less memory) - Libraries diff --git a/user_guide_src/source/database/results.rst b/user_guide_src/source/database/results.rst index 865345762..ac4fc3733 100644 --- a/user_guide_src/source/database/results.rst +++ b/user_guide_src/source/database/results.rst @@ -136,6 +136,26 @@ parameter: | **$row = $query->next_row('array')** | **$row = $query->previous_row('array')** +.. note:: all the functions above will load the whole result into memory (prefetching) use unbuffered_row() for processing large result sets. + +unbuffered_row($type) +===== + +This function returns a single result row without prefetching the whole result in memory as row() does. +If your query has more than one row, it returns the current row and moves the internal data pointer ahead. +The result is returned as $type could be 'object' (default) or 'array' that will return an associative array. + + + + $query = $this->db->query("YOUR QUERY"); + + while ($row = $query->unbuffered_row()) + { + echo $row->title; + echo $row->name; + echo $row->body; + } + *********************** Result Helper Functions *********************** |