Home > php教程 > php手册 > mysql_fetch_array 与 mysql_fetch_object函数与用法

mysql_fetch_array 与 mysql_fetch_object函数与用法

WBOY
Release: 2016-05-24 13:25:24
Original
1179 people have browsed it

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

PHP实例代码如下:

$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; 
    //开源代码phprm.com 
} 
//输出结果为 adsense
Copy after login


教程链接:

随意转载~但请保留教程地址★

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template