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
+12.4k Golang : Get remaining text such as id or filename after last segment in URL path
+19.7k Golang : Close channel after ticker stopped example
+18.6k Golang : Set, Get and List environment variables
+26.1k Mac/Linux and Golang : Fix bind: address already in use error
+10.9k Golang : Command line file upload program to server example
+12.6k Golang : HTTP response JSON encoded data
+5.3k Golang : Customize scanner.Scanner to treat dash as part of identifier
+10.7k Golang : How to delete element(data) from map ?
+36.4k Golang : Convert(cast) int64 to string
+4.7k Javascript : Detect when console is activated and do something about it
+8k Golang : Trim everything onward after a word
+6.8k Golang : Output or print out JSON stream/encoded data