Home  >  Article  >  Backend Development  >  The difference between mysqli_fetch_assoc() and mysqli_fetch_row() in php_PHP tutorial

The difference between mysqli_fetch_assoc() and mysqli_fetch_row() in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:55:511092browse

Using mysqli_fetch_assoc() and mysqli_fetch_row() both returns the query results into an array. Both return the first row and then move the pointer down one row.

Difference: mysqli_fetch_assoc() uses keyword index to obtain the value. For example:
$row = $result->fetch_assoc();
echo $row['username'];

But mysqli_fetch_row() uses a numeric index to obtain the value. For example:
$row = $result->fetch_row();
echo $row[0];//Note: "0" means the first field in the table (i.e. username is the the first field).

There is also a function: mysqli_fetch_object() to get a row back into an object, and then get the value through a class, for example:
$row = $result->fetch_object();
echo $row->username;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364357.htmlTechArticleUsing mysqli_fetch_assoc() and mysqli_fetch_row() both return the query results into an array, and both return the first row and the pointer moves down one row. Difference: mysqli_fetch_assoc() uses keywords...
Statement:
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