Extending the CI_DB_active_record class in codeigniter 2.0
Posted
by
ctrane
on Stack Overflow
See other posts from Stack Overflow
or by ctrane
Published on 2011-02-22T21:08:49Z
Indexed on
2011/03/06
0:10 UTC
Read the original article
Hit count: 139
codeigniter
|activerecord
I am writing my first program with Codeigniter, and have run into a problem. I will start with a focused description of the problem and can broaden it if I need to:
I need to write a multi-dimensional array to the DB and want to use the insert_batch function from the CI_DB_active_record class to do so. The problem is that I need to write empty values as NULL for some fields while other fields need to be empty strings. The current function wraps all values with single quotes, and I cannot find a way to write null values to the database for specified fields.
I would also like to increase the number of records per batch.
I see how to extend models, libraries, etc., but is there a way to extend the CI_DB_active_record class without modifying core classes? The minimal amount of core class modification to make this work that I have found is modifying the following lines in the DB.php file (changing the require_once file to the new file that extends the CI_DB_active_record class and changing the CI_DB_active_record class name to the new class name):
require_once(BASEPATH.'database/DB_active_rec'.EXT);
if ( ! class_exists('CI_DB'))
{
eval('class CI_DB extends CI_DB_active_record { }');
}
Can I do better?
© Stack Overflow or respective owner