PHP Codeigniter 错误:调用未定义的方法 ci_db_mysql_driver::result()
我试图使用 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>';
}
}
?>
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>';
}
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你这里的代码是错误的:
应该是,而是:
现在你可以调用
$query->result()
,因为结果资源是在你实际获取表结果之后才存在的Your code here is wrong:
Should be, instead:
Now you can call
$query->result()
, because the result resource is there after you actually get the table results