因此,我已经在自己的VPS Ubuntu 16中安装了codeigniter
。当我想登录mydomain/admin
时,请输入我的详细信息。如果我按下登录键,则会收到以下错误消息,并且其他成员无法创建帐户。
An uncaught Exception was encountered
Type: Error
Message: Call to a member function result() on boolean
Filename: /var/www/html/application/models/backend/dashboard/Dashboard_model.php
Line Number: 128
回溯:
File: /var/www/html/application/controllers/backend/dashboard/Home.php
Line: 27
Function: monthlyInvestment
File: /var/www/html/index.php
Line: 315
Function: require_once
我在第128行的代码:
return $query = $this->db->query("SELECT MONTHNAME(\`invest_date\`) as month, SUM(\`amount\`) as invest FROM \`investment\` GROUP BY YEAR(\`invest_date\`), MONTH(\`invest_date\`)")->result();
在第27行:
$data['monthlyInvestment'] = $this->dashboard_model->monthlyInvestment();
在315行:
require_once BASEPATH.'core/CodeIgniter.php';
答案 0 :(得分:0)
发生这种情况是因为您的查询返回了布尔值。在这种情况下,由于某些数据库错误,结果为FALSE。我最好的猜测是该错误是因为您试图转义查询字符串中的反引号。进行如下更改,但不要立即返回。
$query = $this->db->query("SELECT MONTHNAME(`invest_date`) as month, SUM(`amount`) as invest FROM `investment` GROUP BY YEAR(`invest_date`), MONTH(`invest_date`)");
// check that $query isn't FALSE, if not return result() else return empty array.
return $query !== FALSE ? $query->result() ? array();
为什么返回一个空数组?如果查询没有失败但没有数据可返回,则result()
将返回相同的内容。