Home > Backend Development > PHP Tutorial > mysql_fetch_array and mysql_fetch_object functions and usage_PHP tutorial

mysql_fetch_array and mysql_fetch_object functions and usage_PHP tutorial

WBOY
Release: 2016-07-13 17:04:25
Original
1151 people have browsed it

mysql_fetch_array and mysql_fetch_object functions and usage

mysql tutorial_fetch_array and mysql_fetch_object functions and usage

$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;
}
//Run the code to prompt Notice: Trying to get property of non-object Okay, let’s modify it now

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


//Output result: adsense 5498bef14143cd98627fb0560cb5ded6
//Now let’s look at an instance of mysql_fetch_object

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

//Comes out after running Fatal error: Cannot use object of type stdClass as array in saying this is not an array

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

//The output result is adsense
/*
Summary:
mysql_fetch_object makes the record an object for processing. For example, when we use classes, we need to use ->Access
mysql_fetch_array saves the record to a data, so you can use $rs['subscript name'] or $rs[0] array number

Original tutorials reprinted on this site indicate the source php tutorialer/php.html">http://www.bKjia.c0m/phper/php.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630874.htmlTechArticlemysql_fetch_array and mysql_fetch_object functions and usage mysql tutorial_fetch_array and mysql_fetch_object functions and usage $conn=mysql_connect(127.0.0.1, root,root); mysql_select_db(ip);...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template