【问题标题】:PHP Codeigniter error: call to undefined method ci_db_mysql_driver::result()PHP Codeigniter 错误:调用未定义的方法 ci_db_mysql_driver::result()
【发布时间】:2012-01-03 17:02:28
【问题描述】:

我试图使用 codeigniter 创建一个 xml 响应。运行代码时会抛出以下错误。

此页面包含以下错误:

第 1 行第 48 列的错误:文档末尾的额外内容

<?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>';
    }
}
?>

【问题讨论】:

  • 你能显示正在解析的最终结果吗?

标签: php xml codeigniter


【解决方案1】:

你这里的代码是错误的:

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

应该是:

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

现在你可以调用$query-&gt;result()了,因为你实际拿到表格结果后结果资源就在那里

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    • 2012-02-06
    • 2015-10-16
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多