CodeIgniter modifications extending database drivers for using them with UNION queries

拈花ヽ惹草 提交于 2019-12-12 03:09:49

问题


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 :(

来源:https://stackoverflow.com/questions/18120338/codeigniter-modifications-extending-database-drivers-for-using-them-with-union-q

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!