gpt4 book ai didi

php - 未定义的属性:CI_DB_mysql_result::$result

转载 作者:行者123 更新时间:2023-11-29 03:54:21 25 4
gpt4 key购买 nike

我是 codeigniter 编程的新手。当我尝试连接数据库并从表中检索数据时,我发现如下错误:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_DB_mysql_result::$result
Filename: models/haii.php
Line Number: 15.

A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/getquery.php
Line Number: 2

我正在使用此代码通过 codeigniter 连接数据库:

Controller :

<?php
class product extends CI_Controller
{
function __construct()
{
}
function getall()
{
$this->load->model('haii');
$data['query']=$this->haii->you();
$this->load->view('getquery',$data);
}
}
?>

型号:

<?php
class haii extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
function you()
{
$query=$this->db->get('member');
return $query->result;
}
}
?>

查看:

<?php
foreach($query as $row)
{
print $row->username;
print $row->password;
print $row->fname;
print $row->lname;
print $row->contact;
print "<br>";
}
?>

最佳答案

you() 函数中使用 return $query->result(); 而不是 return $query->result;result 是方法,不是类成员。

关于php - 未定义的属性:CI_DB_mysql_result::$result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17234924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com