Why I can't Use Admin Dashboard

Asked by At

So, I have installed codeigniter in my VPS Ubuntu 16. When I want to login to mydomain/admin, I enter my details. If I press login, I get the error below plus other members can't create accounts.

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

My code at line 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();

At line 27:

$data['monthlyInvestment'] = $this->dashboard_model->monthlyInvestment();

At line 315:

require_once BASEPATH.'core/CodeIgniter.php';

1 Answers

DFriend On

This happens because your query returns a boolean. In this case FALSE because of some database error. My best guess is the error is because you tried to escape the backticks in your query string. Change it as follows, but don't return it immediately.

$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();

Why return an empty array? That is the same thing that result() would return if the query had not failed but there was no data to return.