简体   繁体   中英

Codeigniter - Call to a member function result_array() on boolean - Local setup Installation error

I require help in codeigniter as a learner. I am trying to do a local setup but its giving the following error.

Fatal error: Call to a member function result_array() on boolean in xampp\\htdocs\\test\\application\\models\\Homemodel.php on line 1144

return $result = $this->db->get()->result_array();

Thank you for help. Stay blessed!!

Try to replace:

return $result = $this->db->get()->result_array();

with

return $this->db->get() ? $this->db->get()->result_array() : [];

It names ternary operator, works similar to if statement :

if ($this->db->get()) {} else {}

This error occurs cause of $this->db->get() returns a boolean value (true/false)

CodeIgniter has an good documentation

visit : https://codeigniter.com/user_guide/database/examples.html

Standard Query With Single Result

"This method returns a single result row. If your query has more than one row, it returns only the first row. The result is returned as an object ."

$query = $this->db->query('SELECT name FROM my_table LIMIT 1');
$row = $query->row();
echo $row->name;

Result Array "This method returns the query result as an array of objects, or an empty array on failure"

$query = $this->db->query("YOUR QUERY");

foreach ($query->result() as $row)
{
    echo $row->title;
    echo $row->name;
    echo $row->body;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM