Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter: Call to a member function result_array() on a non-object
    primarykey
    data
    text
    <p>I'm using Codeigniter to build a webapp and I received this error:</p> <pre><code>Fatal error: Call to a member function result_array() on a non-object in /var/www/application/controllers/people.php on line 29 </code></pre> <p>This is the people.php class:</p> <p> <pre><code>public function __construct() { parent::__construct(); } function People() { } function view($id) { echo "Hello world " . $id; } function all() { $this-&gt;load-&gt;model('people_model', '', TRUE); $allContacts = $this-&gt;people_model-&gt;get_all_contacts(); $results = array(); foreach ($allContacts-&gt;result_array() as $row) { $eachrow = array("personID"=&gt;$row['personID'],"fName"=&gt;$row['fName'],"lName"=&gt;$row['lName'],"phoneNumber"=&gt;"", "emailAddress"=&gt;$row['emailAddress'],"address"=&gt;$row['address'],"city"=&gt;$row['city'],"state"=&gt;$row['state'],"zip"=&gt;$row['zip']); $results = push_array($results, $eachrow); } foreach ($results as $row) { $phoneData = $this-&gt;people_model-&gt;get_phone_by_id($row['personID']); $phoneNumbers = ""; foreach ($phoneData-&gt;result_array() as $row2) { $phoneNumbers = $row2['type'] . " " . $row2['phoneNumber'] . " " . $row2['extension']; } $results['phoneNumber'] = $phoneNumbers; } $data['title']="Page Title Goes Here"; $data['username']="Your Username"; $this-&gt;load-&gt;view('header', $data); $this-&gt;load-&gt;view('people_results', $results); $this-&gt;load-&gt;view('footer'); } } </code></pre> <p>Here is the people_model class:</p> <p> <pre><code>function __construct() { // Call the Model constructor parent::__construct(); } function get_all_contacts() { $query = $this-&gt;db-&gt;query('SELECT * FROM person'); return $query-&gt;result(); } function get_phone_by_id($id) { $query = $this-&gt;db-&gt;query('SELECT * FROM phoneNumber WHERE personID = '.$id); return $query-&gt;result(); } } </code></pre> <p>The only thing I might question in database.php is if the hostname needs a port number, but I don't think that helped when I tried it.</p> <p>I just tried adding (based on similar question in side bar)</p> <pre><code>$this-&gt;mydb = $this-&gt;load-&gt;database('realDB', TRUE); </code></pre> <p>to the people_model and changing the db to mydb and received this error:</p> <pre><code>You have specified an invalid database connection group. </code></pre> <p>and this is my line in database.php:</p> <pre><code>$db['default']['database'] = 'realDB'; </code></pre> <p>Thanks for all your help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload