Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Codeigniter error: call to undefined method ci_db_mysql_driver::result()

I was trying to create an xml response using codeigniter. The following error gets thrown when i run the code.

This page contains the following errors:

error on line 1 at column 48: Extra content at the end of the document

<?php  
class Api extends CI_Controller{  
    
    function index()  
    {
        $this->load->helper('url', 'xml', 'security');
        echo '<em>oops! no parameters selected.</em>';
        
    }
    
    function authorize($email = 'blank', $password = 'blank')
    {
        header ("content-type: text/xml");
        echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
        echo '<node>';
        
        if ($email == 'blank' AND $password == 'blank')
        {
                echo '<response>failed</response>';
        } 
        else 
        {
            $this->db->where('email_id', $email);
            $this->db->limit(1);
            $query = $this->db->from('lp_user_master');
            $this->get();
            $count = $this->db->count_all_results();
            
            if ($count > 0)
            {
                foreach ($query->result() as $row){
                    echo '<ip>'.$row->title.'</ip>';
                }
            }
        }
        echo '</node>';
    }
}
?>
like image 905
Ronnie Avatar asked Nov 22 '11 09:11

Ronnie


1 Answers

Your code here is wrong:

$this->db->where('email_id', $email);
$this->db->limit(1);
$query = $this->db->from('lp_user_master');
$this->get();

Should be, instead:

$this->db->where('email_id', $email);
$this->db->from('lp_user_master'); 
$this->db->limit(1);
$query = $this->db->get();

Now you can call $query->result(), because the result resource is there after you actually get the table results

like image 129
Damien Pirsy Avatar answered Nov 14 '22 20:11

Damien Pirsy