Differences between MySQL_fetch_row () and MySQL_fetch_array ()

Source: Internet
Author: User

The following articles mainly describe the differences between MySQL_fetch_row () and MySQL_fetch_array (). We mainly apply the Code to MySQL_fetch_row () by reading data and related timing () different from MySQL_fetch_array.

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], in this way, the data is read by the array subscript, while the array returned by MySQL_fetch_array () contains both the first and key-value pairs. We can read the data like this if the database field is username, passwd ):

 
 
  1. $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:

Code

 
 
  1. <?php 

Connect to the local MySQL database and select test as the operating database.
 

 
 
  1. $ mysql i = mysqli_connect("localhost", "root", "","test", 3306); 

Use the MySQL_fetch_row () function to read data from the user table

 
 
  1. $result = mysqli_query($mysqli, "SELECT * FROM userinfo");  
  2. while($row = mysqli_fetch_array($result)) 

Read data content cyclically

 
 
  1. {  
  2. ?> 
  3. <tr> 
  4. <td align="center" height="19"><?php echo $row["ID"]?></td> 
  5. <td align="center"><?php echo $row["Name"]?></td> 
  6. <td align="center"><?php echo $row["Detail"]?></td> 
  7. </tr> 
  8. <?php 

Close the connection to the database

 
 
  1. mysqli_free_result($result);  
  2. mysqli_close($mysqli);*/  
  3. ?> 

The above content introduces the differences between MySQL_fetch_row () and MySQL_fetch_array (). I hope you will get some benefits.

Related Article

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.