PHP - mysql mysql_fetch_assoc mysql_fetch_row mysql_fetch_array mysql_fetch_object 区别
2014-11-19 14:57
756 查看
表中数据为:
共五个字段:
+----+----------+---------------------+------------+--------------+
| id | fileName | fileUpTime | fileSize | fileExt |
+----+----------+---------------------+----------+--------------------+
| 1 | qa.html | 2014-11-19 14:53:43 | 3536 | text/html |
+----+----------+---------------------+----------+----------------------+
PHP代码: while ( $row = mysql_fetch_array($result)){
print_r($row);
}
mysql_fetch_assoc:从结果集中取得一行作为关联数组,以字段名作为数组键值
结果为:
Array( [id] => 1 [fileName] => qa.html [fileUpTime] => 2014-11-19 14:53:43 [fileSize] => 3536 [fileExt] => text/html)
mysql_fetch_row :从结果集中取得一行作为关联数组,以数字索引作为数组键值
结果为:
Array( [0] => 1 [1] => qa.html [2] => 2014-11-19 14:53:43 [3] => 3536 [4] => text/html)
mysql_fetch_array :从结果集中取得一行作为关联数组,以数字索引和主键值作为数组键值
结果为:http://www.schonglai.com
Array( [0] => 1 [id] => 1 [1] => qa.html [fileName] => qa.html [2] => 2014-11-19 14:53:43 [fileUpTime] => 2014-11-19 14:53:43 [3] => 3536 [fileSize] => 3536 [4] => text/html [fileExt] => text/html)
mysql_fetch_object:返回一个对象数组
结果为:
stdClass Object( [id] => 1 [fileName] => qa.html [fileUpTime] => 2014-11-19 14:53:43 [fileSize] => 3536 [fileExt] => text/html)
综上: assco 返回 主键 =》 值,
row返回 数字索引 =》 值,
array返回上面两种的和,
object返回对象,以字段名字作为键值。
共五个字段:
+----+----------+---------------------+------------+--------------+
| id | fileName | fileUpTime | fileSize | fileExt |
+----+----------+---------------------+----------+--------------------+
| 1 | qa.html | 2014-11-19 14:53:43 | 3536 | text/html |
+----+----------+---------------------+----------+----------------------+
PHP代码: while ( $row = mysql_fetch_array($result)){
print_r($row);
}
mysql_fetch_assoc:从结果集中取得一行作为关联数组,以字段名作为数组键值
结果为:
Array( [id] => 1 [fileName] => qa.html [fileUpTime] => 2014-11-19 14:53:43 [fileSize] => 3536 [fileExt] => text/html)
mysql_fetch_row :从结果集中取得一行作为关联数组,以数字索引作为数组键值
结果为:
Array( [0] => 1 [1] => qa.html [2] => 2014-11-19 14:53:43 [3] => 3536 [4] => text/html)
mysql_fetch_array :从结果集中取得一行作为关联数组,以数字索引和主键值作为数组键值
结果为:http://www.schonglai.com
Array( [0] => 1 [id] => 1 [1] => qa.html [fileName] => qa.html [2] => 2014-11-19 14:53:43 [fileUpTime] => 2014-11-19 14:53:43 [3] => 3536 [fileSize] => 3536 [4] => text/html [fileExt] => text/html)
mysql_fetch_object:返回一个对象数组
结果为:
stdClass Object( [id] => 1 [fileName] => qa.html [fileUpTime] => 2014-11-19 14:53:43 [fileSize] => 3536 [fileExt] => text/html)
综上: assco 返回 主键 =》 值,
row返回 数字索引 =》 值,
array返回上面两种的和,
object返回对象,以字段名字作为键值。
相关文章推荐
- 【旧资料整理】php mysql_fetch_row,mysql_fetch_array,mysql_fetch_assoc,msql_fetch_object的区别
- [转]mysql_fetch_row,mysql_fetch_array,mysql_fetch_object,mysql_fetch_assoc的区别
- php中mysql_fetch_assoc ,mysql_fetch_array,mysql_fetch_row 三者的区别
- php函数mysql_fetch_row、assoc、array、object的区别
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_object,mysql_fetch_assoc的区别
- mysql_fetch_assoc()和mysql_fetch_array()以及mysql_fetch_row()、mysql_fetch_object()的区别
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_object,mysql_fetch_assoc,的用法及区别
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_object,mysql_fetch_assoc的区别
- php中mysql_fetch_row与mysql_fetch_assoc与mysql_fetch_array()的区别
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_object,mysql_fetch_assoc的区别!
- php mysql_fetch_row, mysql_fetch_array, mysql_fetch_assoc 的区别
- 关于mysql_fetch_row(),mysql_fetch_assoc(),mysql_fetch_array(),mysql_fetch_object(),mysql_result()的区别。
- php 索引,关联数组之mysql_fetch_assoc ,mysql_fetch_array,mysql_fetch_row 三者的区别?
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_assoc以及mysql_fetch_object的区别
- [转]mysql_fetch_row,mysql_fetch_array,mysql_fetch_object,mysql_fetch_assoc的区别
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_object,mysql_fetch_assoc的区别
- mysql_fetch_assoc()和mysql_fetch_array()以及mysql_fetch_row()、mysql_fetch_object()的区别
- php中mysql_fetch_row与mysql_fetch_assoc与mysql_fetch_array()的区别
- php的数据库函数中mysql_fetch_row、mysql_affected_rows、mysql_num_rows的区别
- mysql_fetch_row ,mysql_fetch_assoc. mysql_fetch_array的区别