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
+12k Golang : Reset buffer example
+17.2k Golang : Reset or rewind io.Reader or io.Writer
+5.5k Android Studio : How to detect camera, activate and capture example
+10.5k Golang : convert(cast) string to integer value
+9.4k Golang : Add ASCII art to command line application launching process
+4.7k Golang : Process non-XML/JSON formatted ASCII text file example
+24.5k Golang : Convert CSV data to JSON format and save to file
+6.3k Golang : Handle Palindrome string with case sensitivity and unicode
+8.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+5.4k Golang : Null and nil value
+5.3k Golang : Example of how to detect which type of script a word belongs to
+3.3k Facebook : How to place save to Facebook button on your website