调用未定义的方法ci

调用未定义的方法ci

本文介绍了PHP Codeigniter错误:调用未定义的方法ci_db_mysql_driver :: result()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用codeigniter创建xml响应。当我运行代码时,将引发以下错误。

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

此页面包含以下错误:

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


推荐答案

您的代码在这里是错误的:

Your code here is wrong:

$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(),因为结果资源在您实际获得表结果之后就存在了

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

这篇关于PHP Codeigniter错误:调用未定义的方法ci_db_mysql_driver :: result()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 18:59