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
+6.7k Golang : Get final balance from bit coin address example
+6.1k Golang : get the current working directory of a running program
+32k Golang : Read a text file and replace certain words
+4.9k Golang : Takes a plural word and makes it singular
+11.9k Golang : Get current time
+3.9k Golang : Issue HTTP commands to server and port example
+14.4k Golang : Parse date string and convert to dd-mm-yyyy format
+30.4k Golang : Validate IP address
+13.5k Golang : Execute terminal command to remote machine example
+14.9k Golang : Upload/Receive file progress indicator
+14.5k Golang : Multi threading or run two processes or more example