Welcome Guest, Not a member yet? Register   Sign In
Method Chaining Problem
#1

[eluser]Gyzm[/eluser]
Hello there community.

I have an interesting and possibly challenging issue on my hands and I'm hoping that somebody out there will be able to help me out. As per the title of this post the issue involves method chaining.

I use Method Chaining on everything I do. I LOVE IT! So obviously, every environment that I work in is a PHP 5 environment. When I'm developing I develop locally and then upload the project to the server upon completion. I realize that this isn't an ideal way of doing things and, in the future, I will probably stop. haha. But for now I'm stuck with this issue:

Uploaded project to server
Server is running PHP 5.2.6 (my local dev server is running 5.2.4)
Both are running MySQL

Just to be clear, chaining works on my dev server and doesn't work on the production server.

When I method chain i.e.:
$this->db->select('stuff')->from('here')->where('id', $id)... and so on, I get this error:
___________________________________
| A Database Error Occurred
|
| Error Number: 1096
|
| No tables used
|
| SELECT column_name
___________________________________

If I break up the chain like this:
$this->db->select('stuff');
$this->db->from('here');
$this->db->where('id', $id);

It works and I get what I'm asking for. This is the first time out of at least a dozen servers that I've used CI on that I've encountered this issue. I've tried re-uploading the active record class but the problem persists.

The only prerequisite in the manual for method chaining is PHP 5 which, again, the server is running.

Any takers?

Thanks ahead.
#2

[eluser]danmontgomery[/eluser]
Same result if you use ->get('tablename') instead of ->from('tablename')?

Also: please post actual code, paraphrasing is no help at all.
#3

[eluser]Gyzm[/eluser]
In the interest of keeping it simple I've setup a test controller. So here is ACTUAL code:

Code:
class Test extends Controller{
    

    function works(){
        $this->db->select('*');
        $this->db->from('trips');
        
        $query = $this->db->get();
        
        foreach($query->result() as $row){
            echo $row->title;
        }
    }

    function does_not_work(){
        $this->db->select('*')->from('trips');
        $query = $this->db->get();

        foreach($query->result() as $row){
            echo $row->title;
        }

        // either way both should work
    }

    function also_works(){
        // this is not method chaining
        $this->db->select('*');
        $query = $this->db->get('trips');

        // this would be the equivalent of
        // $query = $this->db->get('trips');

        foreach($query->result() as $row){
            echo $row->title."<br>";
        }
    }
}

I wanted to see what was happening in DB_active_rec.php so I put a print_query() function in. I took everything up to and including $this->_compile_select(); in the get() function and when method chaining you only get "SELECT *" which is outputted by the error message. When you don't use method chaining the string is compiled properly.

Interestingly this does work:
Code:
function this_also_works(){
        $query = $this->db->select('title')->where('id', '2')->get('trips');
        //$query = $this->db->get();

        foreach($query->result() as $row){
            echo $row->title;
        }
    }

Even more interesting is this:
Code:
function this_also_works(){
        $query = $this->db->select('title')->from('trips')->where('id', '2')->get();
        //$query = $this->db->get();

        foreach($query->result() as $row){
            echo $row->title;
        }
    }

...
Ah well nevermind. I'll just rewrite everything like this.

Thanks
#4

[eluser]Gyzm[/eluser]
Please ignore this post. My problem has turned out to be an issue with the hosting.

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB