首頁  >  文章  >  後端開發  >  mysql_fetch_array 与 mysql_fetch_object函数与用法_PHP教程

mysql_fetch_array 与 mysql_fetch_object函数与用法_PHP教程

WBOY
WBOY原創
2016-07-13 17:04:251082瀏覽

mysql_fetch_array 与 mysql_fetch_object函数与用法

mysql教程_fetch_array  与 mysql_fetch_object函数与用法

$conn=mysql_connect("127.0.0.1","root","root");
 mysql_select_db("ip");
 $sql="select * from adminblog  ";
 $result=mysql_query($sql,$conn);
    
 while($rs=mysql_fetch_array($result))
        {
   echo $rs->username;
   echo $rs->password;
  }
//运行代码提示Notice: Trying to get property of non-object 好了,我们现在修改一下

while($rs=mysql_fetch_array($result))
        {
   echo $rs['username'];
   echo $rs['password'];
  }


 //输出结果: adsense 5498bef14143cd98627fb0560cb5ded6
//现在来看一个mysql_fetch_object的实例

 

 

while($rs=mysql_fetch_object($result))
        {
   echo $rs['username'];
   
  }

//运行后出来 Fatal error: Cannot use object of type stdClass as array in 说这不是一个数组

 

while($rs=mysql_fetch_object($result))
        {
   echo $rs->username;
   
  }

//输出结果为 adsense
/*
总结:
mysql_fetch_object 把记录作来一个对象来处理,像我们用类时就要用->访问
mysql_fetch_array 把记录保存到一个数据所以可以用$rs['下标名'] 或$rs[0]数组编号

本站原创教程转载注明来源php教程er/php.html">http://www.bKjia.c0m/phper/php.html

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/630874.htmlTechArticlemysql_fetch_array 与 mysql_fetch_object函数与用法 mysql教程_fetch_array 与 mysql_fetch_object函数与用法 $conn=mysql_connect(127.0.0.1,root,root); mysql_select_db(ip);...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn