CodeIgniter modifications extending database drive

2019-08-17 00:08发布

My goal is to use UNION queries in CodeIgniter Active Record.

Some people suggested to me to use the method $this->db->last_query(); to get the queries I want, then combining it with UNION.

Problem is that $this->db->from(); method used in the MySQL driver in Active Record uses parenthesis around the from clause (ex: SELECT * FROM ('table') ) and prevents me to use UNION.

So I checked again and found I could modify the _from_tables function defined in the

system/database/drivers/mysql/mysql_driver.php

I changed the code :

function _from_tables($tables)
{
    if ( ! is_array($tables))
    {
        $tables = array($tables);
    }
return '('.implode(', ', $tables).')';
}

to this :

function _from_tables($tables)
{
    if ( ! is_array($tables))
    {
        $tables = array($tables);
    }
return implode(', ', $tables);
}

But if I I asked a question here on how to extend CI mysql driver (in fact, I only want to replace the from method with a custom one) : CodeIgniter Hooks for Active Record library and I was proposed to ask a new question.

So one user proposed to add two files, which I did, in my folders:

application/libraries/MY_DB_mysql_driver.php
application/core/MY_Loader.php

I get these errors while using this method :

 A PHP Error was encountered Severity: 8192 Message: Assigning the return value of new by reference is deprecated Filename: core/MY_Loader.php Line Number: 32

So I modified the script he gave me (you can see it at https://github.com/EllisLab/CodeIgniter/wiki/Extending-Database-Drivers) by deleting the & in :

$db =& new $my_driver(get_object_vars($db)); 

I now get the following error :

Fatal error: Call to undefined method MY_DB_mysql_driver::where() in \system\libraries\Session.php

If someone has done it without tweaking system folder, please help :(

0条回答
登录 后发表回答