PHP Codeigniter 错误:调用未定义的方法 ci_db_mysql_driver::result()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8224655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Codeigniter error: call to undefined method ci_db_mysql_driver::result()
提问by Ronnie
I was trying to create an xml response using codeigniter. The following error gets thrown when i run the code.
我试图使用 codeigniter 创建一个 xml 响应。当我运行代码时抛出以下错误。
This page contains the following errors:
此页面包含以下错误:
error on line 1 at column 48: Extra content at the end of the document
第 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>';
}
}
?>
回答by Damien Pirsy
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
现在可以调用了$query->result()
,因为实际得到表结果后,结果资源就在那里了