PHP functions Mysql_fetch_row, Assoc, array, object differences
First, Mysql_fetch_row
This function takes a row from the result set as the enumeration data, obtains a row of data from the result set associated with the specified result identity, and returns it as an array. Each result column is stored in an array of cells, with an offset starting at 0.
Note that this is offset from 0, that is, you cannot use the field name to take the value, only the index to get the value. For example:
while ($row = Mysql_fetch_row ($res)) {
echo $row [' CID ']. >>> '. $row [1]. '
';
}
Here the $row[' CID '] does not get the value, $row [1] can be taken.
Second, MYSQL_FETCH_ASSOC
Take a row from the result set as an associative array, which means that the function cannot be indexed as Mysql_fetch_row, but only with the field name. For example:
while ($row = Mysql_fetch_assoc ($res)) {
echo $row [' CID ']. >>> '. $row [1]. '
';
}
Here $row[1] This is not the value, $row [' CID '] can be taken.
Third, Mysql_fetch_array
Take a row from the result set as an associative array, or as a numeric array, or both, in addition to storing the data in a numeric index in an array, you can also store the data as an associated index, using the field name as the key name.
That means he gets the result like an array, you can use a key or index to take a value. For example:
while ($row = Mysql_fetch_array ($res)) {
echo $row [' CID ']. >>> '. $row [1]. '
';
}
Here $row[' CID '], $row [1] can get the corresponding value.
The functions of Mysql_fetch_row and MYSQL_FETCH_ASSOC add up to Mysql_fetch_array.
Iv. Mysql_fetch_object
As the name implies, take a row from the result set as an object and make the field name a property. So this is the only way to get the value:
while ($row = Mysql_fetch_object ($res)) {
echo $row->cid. ' >>> '. $row->title.
";
}
http://www.bkjia.com/PHPjc/955270.html www.bkjia.com true http://www.bkjia.com/PHPjc/955270.html techarticle PHP Functions Mysql_fetch_row, Assoc, array, object The difference one, mysql_fetch_row this function is to take a row from the result set as the enumeration data, from and specify the results of the associated results identified ...