When I write php, an error will appear, as shown in the code below. Fatal error: Cannot use object of type stdClass as array
When I write php, an error will appear, as shown in the code below
Fatal error: Cannot use object of type stdClass as array
If you have no experience with this question, you may not understand why. Let’s take a look at my code below.
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','unknown','unknown','unknown');
}
}
Do you see what’s going on?
$rs = mysql_fetch_object($result);
Look at this or below, and then look at this below
return array($rs['sex'],$rs['born'],$rs['reg_time'],'/boke/'.$rs['my_photo'],$rs['id' ]);
Did you see it? I used the $rs[] data access format for the time used above after objcect and the time used below. Of course, an error will be prompted.
Okay, the problem is solved.