In-depth mysql_fetch_row () and mysql_fetch_array () the difference between the detailed _php example

Source: Internet
Author: User
These two functions return an array, the difference being that the first function returns an array that contains only the values we can only $row[0],
$row [1], which reads the data as an array subscript, and mysql_fetch_array () returns an array that contains both the first and key values
On the form, we can read the data in this way (if the database field is USERNAME,PASSWD):
$row [' username '], $row [' passwd ']
Furthermore, if you use ($row as $kay => $value), you can also get the field name of the database directly.
More important, Mysqli is a new library of functions provided by PHP5, and (i) represents an improvement that performs faster.
For example
Copy Code code as follows:

Code highlighting produced by Actipro Codehighlighter (freeware) http://www.CodeHighlighter.com/--><?php
Connect to local MySQL database, select Test as Action Library
$mysqli = Mysqli_connect ("localhost", "root", "" "," Test ", 3306);
Reading data from the user table using the Mysql_query function
$result = Mysqli_query ($mysqli, "SELECT * from UserInfo");
while ($row = Mysqli_fetch_array ($result))//Read data content by looping
{
?>
<tr>
<TD align= "center" height= "><?php echo $row [" ID "]?></td>
<TD align= "center" ><?php Echo $row ["Name"]?></td>
<TD align= "center" ><?php Echo $row ["Detail"]?></td>
</tr>
<?php
}
To close a connection to a 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.