Detailed explanation of the difference between mysql_fetch_row() and mysql_fetch_array()_PHP Tutorial

WBOY
Release: 2016-07-21 15:09:19
Original
759 people have browsed it

These 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], so use the array subscript. Read the data, and the array returned by mysql_fetch_array() contains both the first type and the form of key-value
pairs. We can read the data like this, (if the database fields are username, passwd):
$row['username'], $row['passwd']
Moreover, if you use ($row as $kay => $value) to operate, you can also directly obtain the fields of the database name.
The more important thing is that mysqli is a new function library provided by php5. (i) means improvement and its execution speed is faster.
For example:

Copy code The code is as follows:

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->//Connect to the local mysql database, select test as the operation library
$mysqli = mysqli_connect("localhost", "root", "","test", 3306);
//Use the mysql_query function from user Read data from the table
$result = mysqli_query($mysqli, "SELECT * FROM userinfo");
while($row = mysqli_fetch_array($result))//Read the data content through loop
{
?>

     
      

}
//Close the connection to the database
mysqli_free_result ($result);
mysqli_close($mysqli);*/
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327342.htmlTechArticleBoth functions return an array. The difference is that the array returned by the first function only contains Value, we can only $row[0], $row[1], so we can read data using array subscripts, and my...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template