PHP中mysql_fetch_array()和mysql_fetch_row()的区别
2009-11-08 00:00
549 查看
最近在做PHP与数据库交互的project,急于求成,模仿了下例子就开始动手,结果误把mysql_fetch_array写成了mysql_fetch_row,囧事来了,发现返回的数组居然是index=>value的形式,而明明记得是field name=>value的哈,查手册才明白。
1. mysql_fetch_array的函数原型是
array mysql_fetch_array ( resource $result [, int $result_type= MYSQL_BOTH ] )
Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
The type of returned array depends on how result_type is defined. By using MYSQL_BOTH (default), you'll get an array with both associative and number indices. Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works).
2. 这就很明白了,若设定不同的参数,mysql_fetch_array()可以做到mysql_fetch_row()和mysql_fetch_assoc()的功能,而后两个函数就只接受第一个参数,返回的分别是associative=>value, index=>value的数组
3.MYSQL_BOTH是什么效果呢,测试了下
Sql: select firstname,lastname from table where id="c01";
$array=mysql_fetch_array($result,MYSQL_BOTH);
$array[0]和$array['firstname']一样
1. mysql_fetch_array的函数原型是
array mysql_fetch_array ( resource $result [, int $result_type= MYSQL_BOTH ] )
Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
The type of returned array depends on how result_type is defined. By using MYSQL_BOTH (default), you'll get an array with both associative and number indices. Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works).
2. 这就很明白了,若设定不同的参数,mysql_fetch_array()可以做到mysql_fetch_row()和mysql_fetch_assoc()的功能,而后两个函数就只接受第一个参数,返回的分别是associative=>value, index=>value的数组
3.MYSQL_BOTH是什么效果呢,测试了下
Sql: select firstname,lastname from table where id="c01";
$array=mysql_fetch_array($result,MYSQL_BOTH);
$array[0]和$array['firstname']一样
相关文章推荐
- 【旧资料整理】php mysql_fetch_row,mysql_fetch_array,mysql_fetch_assoc,msql_fetch_object的区别
- php mysql_fetch_row, mysql_fetch_array, mysql_fetch_assoc 的区别
- php中mysql_fetch_row() 和mysql_fetch_array之间有什么区别
- PHP mysql_fetch_array与mysql_fetch_row的区别
- php中mysql_fetch_row() 和mysql_fetch_array之间有什么区别
- php中mysql_fetch_assoc ,mysql_fetch_array,mysql_fetch_row 三者的区别
- php 索引,关联数组之mysql_fetch_assoc ,mysql_fetch_array,mysql_fetch_row 三者的区别?
- php中mysql_fetch_row与mysql_fetch_assoc与mysql_fetch_array()的区别
- php中mysql_fetch_row与mysql_fetch_assoc与mysql_fetch_array()的区别
- [转]mysql_fetch_row,mysql_fetch_array,mysql_fetch_object,mysql_fetch_assoc的区别
- mysql中fetch_array, fetch_accoc, fetch_row,fetch_object的区别
- mysql和mysqli,fetch_row()和fetch_array()区别
- php mysql_fetch_array与mysql_fetch_assoc的区别
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_assoc的区别
- mysql_fetch_assoc和mysql_fetch_array、mysql_fetch_row的区别
- mysql_fetch_row() 与 mysql_fetch_array() 的区别
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_assoc的区别
- mysql_fetch_row ,mysql_fetch_assoc. mysql_fetch_array的区别
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_assoc的区别
- PHP - mysql mysql_fetch_assoc mysql_fetch_row mysql_fetch_array mysql_fetch_object 区别