This is a subquery library for CodeIgniter’s active record class. It lets you use the active record methods to create subqueries in your SQL.
CodeIgniter 1.7.x - 2.0.2 (Works with 2.1.x, but some modifications are required)
then load it in your code using
I guess you can add
/application/config/autoload.php), if you want.
This library doesn't work with CodeIgniter 2.1.x out of the box. It requires modifications to a file in
/system to make it work.
You need to edit
/system/database/DB_active_rec.php and modify the signature of
_compile_select (should be line 1673). In the older version(s) of CodeIgniter, this function was not protected, so if you remove the protected keyword from the function, my library will work.
(There's probably a reason this function is protected.)
In the develop version of CodeIgniter (which works with this library just fine, by the way), there is a public function that you can use. You can "steal" the
get_compiled_select function from the
/system/database/DB_query_builder.php file (line 1283).
Put this function inside
* Get SELECT query string
* Compiles a SELECT query string and returns the sql.
* @param string the table name to select from (optional)
* @param bool TRUE: resets QB values; FALSE: leave QB vaules alone
* @return string
public function get_compiled_select($table = '', $reset = TRUE)
if ($table !== '')
$select = $this->_compile_select();
if ($reset === TRUE)
My library will check for the existance of either a
get_compiled_select method. If none of these methods exist, the library will fail to load.
You can also clone the project with Git by running:
$ git clone git://github.com/NTICompass/CodeIgniter-Subqueries