您的位置:首页 > 移动开发 > Objective-C

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返回对象,以字段名字作为键值。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐