The error Fatal error: Cannot use object of type stdClass as array appears when I write php.
When I write php, errors may occur, such as code errors.
Fatal error: Cannot use object of type stdClass as array
This problem indicates that if you have no experience, you may not be able to see it. Let's take a look at my code.
Function get_userinfo ($ id ){
$ SQL = "Select * from @ # _ debbs where username = '$ id '";
$ Result = mysql_query ($ SQL) or die ('E ');
If (mysql_num_rows ($ result )){
$ Rs = mysql_fetch_object ($ result );
Return array ($ rs ['sex'], $ rs ['born'], $ rs ['reg _ time'], '/boke /'. $ rs ['my _ photo '], $ rs ['id']);
} Else {
Return array ('parameter error', 'unknown ', 'unknown ');
}
}
Do you see what's going on?
$ Rs = mysql_fetch_object ($ result );
Look at the above or, and then look at the following
Return array ($ rs ['sex'], $ rs ['born'], $ rs ['reg _ time'], '/boke /'. $ rs ['my _ photo '], $ rs ['id']);
Did you see it? I used $ rs [] for data access after objcect. Of course, an error will be prompted.
Okay, the problem is solved.