在我寫php是會出現,如下圖代碼提供錯誤
Fatal error: Cannot use object of type stdClass as array
這個問題看提示如果沒有經驗的朋友可能看不出所以然來,下面我們就來看看我這段代碼。
- 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('參數錯誤','未知','未知','未知','未知','未知');
- }
- }
各位看出來是怎么回事了嗎?
- $rs = mysql_fetch_object($result);
看看上面這或,再看看下面
- return array($rs['sex'],$rs['born'],$rs['reg_time'],'/boke/'.$rs['my_photo'],$rs['id']);
看出來了沒?我上面是以objcect后下面用的時間又用$rs[]數據訪問形式,當然就會提示出錯哦。
新聞熱點
疑難解答