mysql_fetch_row() 和mysql_fetch_array之间有什么区别?

解决方案 »

  1.   

    这两个函数,返回的都是一个数组,区别就是第一个函数返回的数组是只包含值,我们只能$row[0],$row[1],这样以数组下标来读取数据,而MySQL_fetch_array()返回的数组既包含第一种,也包含键值对的形式,我们可以这样读取数据,(假如数据库的字段是 username,passwd):$row['username'], $row['passwd'] 
      

  2.   

    mysql_fetch_row是从结果集取出1行数组,作为枚举 mysql_fetch_array是从结果集取出一行数组作为关联数组,或数字数组,两者兼得
    eg:
    $sql="select abc,def from a";
    $res=mysql_query($sql);那么:
    $row=mysql_fetch_row($res);
    $row结果是两个:$row[0]和$row[1]
    那么:
    $row=mysql_fetch_array($res);
    $row结果是4个:$row[0]、$row[1]、$row["abc"]和$row["def"]
      

  3.   

    你print_r();就知道了。mysql_fetch_row()返回数字数组,
    而mysql_fetch_array()函数从结果集中取得一行作为关联数组,或数字数组,或二者兼有。依据第二个参数的值。返回不同结构的数组。参考: http://www.w3school.com.cn/php/func_mysql_fetch_array.asp