Custom backport of unbuffered_row in CI2 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18) +--- Thread: Custom backport of unbuffered_row in CI2 (/showthread.php?tid=64039) |
Custom backport of unbuffered_row in CI2 - includebeer - 01-06-2016 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') 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 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. RE: Custom backport of unbuffered_row in CI2 - includebeer - 01-06-2016 Ok, obviously, the num_rows variable is not set before calling result_array() (this is for my other queries not using unbuffered_row). So I should change this : PHP Code: if($query->num_rows > 0) To this : PHP Code: if($query->num_rows() > 0) And I think it will work... RE: Custom backport of unbuffered_row in CI2 - includebeer - 01-07-2016 One last change, num_rows must be set to 0. Now I think it works. PHP Code: // oci8 vars must be set before calling this @Narf, @kilishan, I'd like your feedback on this. Am I shooting myself in the foot? |