CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
There are times when the error message returned by the interpreter or compiler just don't make sense. Today I encountered an error message while I was coding up CodeIgniter today and the error message is :
Fatal error: Cannot use object of type stdClass as array
After reading up CodeIgniter user guide, apparently the error was caused by the wrong way of accessing result
array returned by the $this->db->query()
function.
To get rid of the error message, change the $row['username']
to $row->username
foreach ($results->result() as $row){
$username = $row['username'];
}
change to
foreach ($results->result() as $row) {
$username = $row->username;
}
Hope this tutorial can be useful to you when coding in CodeIgniter Framework
Reference :
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+7.7k Golang : Getting Echo framework StartAutoTLS to work
+20k Golang : How to get own program name during runtime ?
+8.9k Golang : Handle sub domain with Gin
+5.8k Facebook : How to force facebook to scrape latest URL link data?
+13.5k Golang : Set image canvas or background to transparent
+5.1k JavaScript/JQuery : Redirect page examples
+36.1k Golang : How to split or chunking a file to smaller pieces?
+6.7k Swift : substringWithRange() function example
+29.2k Golang : Save map/struct to JSON or XML file
+18.5k Golang : Iterating Elements Over A List
+33.8k Golang : Call a function after some delay(time.Sleep and Tick)