Cannot use object of type stdClass as array

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.