Difference between mysql_fetch_array and mysql_fetch_row?

前端 未结 10 1365
野的像风
野的像风 2020-12-02 08:36

This is a simple question for PHP users. The reason I couldn\'t get the the exact difference between mysql_fetch_array() and mysql_fetch_row() in P

10条回答
  •  天命终不由人
    2020-12-02 09:38

    Many of the php programming newbies get confused about mysql_fetch_array(), mysql_fetch_row(), mysql_fetch_assoc() and mysql_fetch_object() functions, but all of these functions performs a similar process.

    Let us create a table “tb” for clear example with three fields “id”, “username” and “password”

    Table: tb

    Insert a new row into the table with values 1 for id, tobby for username and tobby78$2 for password

    enter image description here

    db.php

    
    

    mysql_fetch_row()

    Fetch a result row as an numeric array

    
    
    
    

    Result

    1 tobby tobby78$2

    mysql_fetch_object()

    Fetch a result row as an object

    
    id;
    echo $row->username;
    echo $row->password;
    ?>
    
    

    Result

    1 tobby tobby78$2

    mysql_fetch_assoc()

    Fetch a result row as an associative array

    
    
     
    

    Result

    1 tobby tobby78$2

    mysql_fetch_array()

    Fetch a result row as an associative array, a numeric array and also it fetches by both associative & numeric array.

    
    /* here both associative array and numeric array will work. */
    
    echo $row[0];
    echo $row[1];
    echo $row[2];
    
    ?>
    
    

    Result

    1 tobby tobby78$2

提交回复
热议问题