Home >Backend Development >PHP Tutorial >Usage of mysql_fetch_array() function in php

Usage of mysql_fetch_array() function in php

WBOY
WBOYOriginal
2016-07-25 08:56:501680browse
This article introduces the usage of the mysql_fetch_array() function in PHP, which returns data query results in the form of an array. Friends in need can refer to it.

php data query result function: mysql_fetch_array() function. Return data query results in array form.

Syntax: array mysql_fetch_array(int result, int [result_typ]);

Return value: array Function type: Database function

This function is used to split the query result result into an array variable. If result has no data, a false value is returned. This function is an enhanced function of mysql_fetch_row(). In addition to putting the returned column and numeric index into the array, you can also put the text index into the array.

If several return fields have the same text name, the last field inserted is valid. Solution: Use numeric indexes or use aliases for columns with the same name.

Note: The processing speed of using this function is actually not slower than the mysql_fetch_row() function. Which function to use depends on the needs of use. The parameter result_typ is a constant value, including the following constants: MYSQL_ASSOC, MYSQL_NUM and MYSQL_BOTH.

Having said so much, let’s look at an example. Output all rows of the a_id and a_name fields in the database table. Code:

<?php
/**
* mysql_fetch_array() 返回数组形式的查询结果
* by bbs.it-home.org
*/
$conn = mysql_connect("服务器名","用户名","密码"); 
mysql_select_db("数据库名", $conn);
$result = mysql_query("select * from table", $conn); 
while($row = mysql_fetch_array($result)) { 
echo $row["a_id"]; 
echo $row["a_name"]; 
} 
mysql_free_result($result); 
?>


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