php Codeigniter - error while executing library Subquery.php

ぐ巨炮叔叔 提交于 2019-12-13 04:41:57

问题


I have been using a library for subqueries to work - Subquery.php Ref : https://github.com/NTICompass/CodeIgniter-Subqueries

$this->db->select('test');
$this->db->select('test2');
$this->db->from('table');
$sub = $this->subquery->start_subquery('where_in');
$sub->select('IDs');
$sub->from('idTable');
$sub->where('date', '2011-07-10');
$this->subquery->end_subquery('id');

I think that this statement:

$sub = $this->subquery->start_subquery('where_in');

contains the error. When I execute this line, I get a blank page. The fn. start_subquery is:

function start_subquery($statement, $join_type = '', $join_on = 1){
        $db = $this->CI->load->database('', true); // after executing this statement, a blank page shows...
        $this->dbStack[] = $db;
        $this->statement[] = $statement;
        if(strtolower($statement) == 'join'){
            $this->join_type[] = $join_type;
            $this->join_on[] = $join_on;
        }
        return $db;
    }

FYI - In my database.php:

$active_group = 'default'
$active_record = TRUE;

And CI version is 2.1.0


回答1:


Hm, understand. As I see the subquery's source code in line 27, it wants to call _compile_select or get_compiled_select. If you can check in CI's DB_active_rec.php the _compile_select is protected so you can't access from Subquery (it isn't subclass of db).

Possible solution: _compile_select() should public or class Subquery should be extend of CI's db class. I think you should report this to author of Subquery.

Or you can extend the CI's db class :)

Sorry - I want to write it as a comment.




回答2:


Thanks, I have changed the stmt. class Subquery to class Subquery extends CI_DB_active_record in Subquery.php and it is working fine. And yes, I will report this to the author. :)




回答3:


I wrote that library, so thanks for using it. The problem is (as @uzsolt has stated) is that _compile_select is protected. It used to not be in CodeIgniter 1.7.x (it was just a neat hidden method some devs found).

In the dev version of CodeIgniter on GitHub (https://github.com/EllisLab/CodeIgniter), there is a public get_compiled_select method. Seems this change hasn't been pushed to the stable build yet.

So, to get this library to work, you can try using the development version of CodeIgniter. I'm pretty sure they are going to remove the ability to extend CI_DB_active_record in the future (http://codeigniter.com/user_guide/general/creating_libraries.html).



来源:https://stackoverflow.com/questions/10768582/php-codeigniter-error-while-executing-library-subquery-php

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