In-depth explanation of the differences between mysql_fetch_row () and mysql_fetch_array ()

Source: Internet
Author: User

The two functions return an array. The difference is that the array returned by the first function only contains values. We can only $ row [0].
$ Row [1], which reads data by the array subscript. The array returned by mysql_fetch_array () contains both the first and key values.
In the correct format, we can read data like this (if the database field is username, passwd ):
$ Row ['username'], $ row ['passwd']
In addition, if you use ($ row as $ kay => $ value) for operations, you can directly obtain the database field name.
What's more, mysqli is a new function library provided by php5. (I) indicates improvement and its execution speed is faster.
For example:
Copy codeThe Code is as follows:
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/--> <? Php
// Connect to the local mysql database and select test as the operating database
$ Mysqli = mysqli_connect ("localhost", "root", "", "test", 3306 );
// Use the mysql_query function to read data from the user table
$ Result = mysqli_query ($ mysqli, "SELECT * FROM userinfo ");
While ($ row = mysqli_fetch_array ($ result) // read data through Loop
{
?>
<Tr>
<Td align = "center" height = "19"> <? Php echo $ row ["ID"]?> </Td>
<Td align = "center"> <? Php echo $ row ["Name"]?> </Td>
<Td align = "center"> <? Php echo $ row ["Detail"]?> </Td>
</Tr>
<? Php
}
// Close the connection to the database
Mysqli_free_result ($ result );
Mysqli_close ($ mysqli );*/
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.