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 nowwhile($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