Welcome Guest, Not a member yet? Register   Sign In
Custom backport of unbuffered_row in CI2
#1

In a CI2 project I work on, I really need the unbuffered_row() function that exists only in CI3. The project will be migrated to CI3 later this year, but for now I want to add the function in CI2 to address a memory issue. Here are the changes I made. Can someone knowing very well how the database classes works,  tell me if those changes will cause problems? Especially the removal of the call to num_rows().

This is what I added to system/database/DB_result.php:
PHP Code:
public function unbuffered_row($type 'object')
{
    if (
$type === 'array')
    {
        return 
$this->_fetch_assoc();
    }
    elseif (
$type === 'object')
    {
        return 
$this->_fetch_object();
    }

    
/*
     * _fetch_object has no parameter in CI2, and I don't need it anyway, so I'm throwing an exception here.
     */
    // return $this->_fetch_object($type);

    
throw new Exception("Invalid type ($type)");


In system/database/DB_driver.php, near the end of the query() function, I removed the call to num_rows() because it fetched all the rows. Also, it's not there in CI3, and for now I haven't seen any problem:
PHP Code:
// oci8 vars must be set before calling this
/* $RES->num_rows = $RES->num_rows();     REMOVED */ 


So, will it work? Thank you for your feedback!

PS: I know very well it's a bad idea to make changes to core classes, but it's a temporary fix. The project will be migrated to CI3 later this year.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply


Messages In This Thread
Custom backport of unbuffered_row in CI2 - by includebeer - 01-06-2016, 09:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB