PHP Codeigniter 错误:调用未定义的方法 ci_db_mysql_driver::result()

标签 php xml codeigniter

我试图使用 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>';
    }
}
?>

最佳答案

你这里的代码是错误的:

$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->result()了,因为result资源是在你真正拿到表结果之后才存在的

关于PHP Codeigniter 错误:调用未定义的方法 ci_db_mysql_driver::result(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8224655/

相关文章:

php - 如何使用 PHPUnit 模拟 SimpleXMLElement 对象?

使用 Golang 进行 XML 编码 - 具有相同节点名称的多个节点

python - 使用pyxll将python集成到excel中...... lxml模块有问题

codeigniter - 使用 codeigniter 发送新闻通讯的最佳解决方案

php - 使用 Codeigniter 在每个页面加载时执行代码?

javascript - 数据库更新后php/javascript更改内联标签

php - 为什么我的 cron 任务在命令行中有效,但在 PLESK 中无效?

php - MYSQL不等于'<>'不起作用。怎么解决呢?

php - Ebay Api - 使用 php 添加产品

java - 使用 XML 格式化日期