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
+8.6k Golang : Combine slices but preserve order example
+6k PageSpeed : Clear or flush cache on web server
+17.2k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+10.1k Golang : How to tokenize source code with text/scanner package?
+36.3k Golang : Save image to PNG, JPEG or GIF format.
+19.8k Golang : Measure http.Get() execution time
+31.4k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+17.4k Golang : Multi threading or run two processes or more example
+16.3k Golang : Convert slice to array
+5.9k Golang : Compound interest over time example
+5.2k Golang : The Tao of importing package