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.3k Golang : Display list of countries and ISO codes
+11.1k Golang : Read until certain character to break for loop
+32.4k Golang : Math pow(the power of x^y) example
+8.2k Golang : Find relative luminance or color brightness
+6.6k Golang : How to determine if request or crawl is from Google robots
+20.7k Golang : Read directory content with os.Open
+18.2k Golang : Get command line arguments
+36.4k Golang : How to split or chunking a file to smaller pieces?
+12k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+14k Golang : Human readable time elapsed format such as 5 days ago
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+7.4k Golang : Accessing dataframe-go element by row, column and name example