Welcome Guest, Not a member yet? Register   Sign In
Possible to extend the database library?
#1

[eluser]louis w[/eluser]
Can you extend the database drivers to be able to make modifications? I tried the code below with no avail.

Code:
// ./libraries/MY_DB_active_record.php
class MY_DB_active_record extends CI_DB_active_record {    

    public function __construct() {
        
        parent::__construct();
        echo '<p>' . __CLASS__ . '</p>';
    }

}
#2

[eluser]jedd[/eluser]
[quote author="louis w" date="1255548242"]
Can you extend the database drivers to be able to make modifications?
[/quote]

What kind of modifications are you wanting to do? You may be able to do what you want to be able to do by extending the Model.

From the CI User Guide:
Quote:
Note: The Database classes can not be extended or replaced with your own classes, nor can the Loader class in PHP 4. All other classes are able to be replaced/extended.

The wiki contains [url="http://codeigniter.com/wiki/Extending_Database_Drivers/"]this page[/url] on extending the database drivers, but presumably you searched the wiki before posting .. and so I guess this wasn't a good enough answer for you. Mind, you would have read the CI User Guide before posting too, I suppose.
#3

[eluser]louis w[/eluser]
Actually I did not see that in the manual hence why I was posting a message in this forum. I was hoping for encouraging help from the CI community.

I was planning to add in support for the SQL_CALC_FOUND_ROWS function.
#4

[eluser]pistolPete[/eluser]
Have a look at http://codeigniter.com/wiki/Extending_Database_Drivers/.
#5

[eluser]jedd[/eluser]
Does count_all_results() not do it for you?

SQL_CALC_FOUND_ROWS is MySQL specific, AFAIK, so the AR class might not be the best place for it. Can you not do what you want to do within MY_Model?

Is your 'encouraging help' reference ever so slightly sarcastic? Tsk tsk - I gave you a link to the official documentation page that clearly states that you can't do what you're trying to do AND I gave you a link to a web page that describes how you can do what you're trying to do.

pistolPete - I know I hid it a bit, but thanks for re-iterating the link into the wiki. Wink
#6

[eluser]louis w[/eluser]
I do appreciate your help and links, the sarcasm was in reply to your tone.

Am going to investigate adding this to my extended model and duplicating most of the actions of the get method in CI_DB_active_record and adding SQL_CALC_FOUND_ROW. It looks like you are able to call methods like _compile_select from outside the class.

Thanks for the pointers.
#7

[eluser]skeptic35[/eluser]
Actually I think it would be great if CI was supporting this natively or at least would provide a method to get native database functions into the select statement. I.e. something like "SELECT NOW()" or the above mentioned "SELECT SQL_CALC_FOUND_ROWS".
Some sort of "don't protect fields" option would be enough.

It's a bit annoying that I have to write the entire select statement manually (including where and joins and whatnot) just because I'd like to use a native database function.
#8

[eluser]nkm82[/eluser]
Actually, it supports it. From the user guide:

Quote:$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

Code:
$this->db->select('SELECT SUM(payments.amount) AS amount_paid', FALSE);
$query = $this->db->get('mytable');

http://ellislab.com/codeigniter/user-gui...tml#select

By the way, note that MySQL doesn't cache read queries that use native functions.
#9

[eluser]skeptic35[/eluser]
Duh. Thanks for that :-)
Totally overlooked that one.
#10

[eluser]louis w[/eluser]
Ditto on that duh, no idea how I overlooked that one Smile




Theme © iAndrew 2016 - Forum software by © MyBB