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
+13.7k Golang : How to check if IP address is in range
+6.7k Gogland : Where to put source code files in package directory for rookie
+5k Golang : Function as an argument type example
+9.5k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+15.6k Golang : Get own process identifier
+5.7k Golang : Check if password length meet the requirement
+12.6k Golang : Fix image: unknown format error
+5.8k Mac/Linux/Windows : Get CPU information from command line
+14.6k Golang : How to reverse elements order in map ?
+22.9k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+5.2k Golang : Join lines with certain suffix symbol example
+7.6k Golang : Gaussian blur on image and camera video feed examples