Home  >  Article  >  Backend Development  >  What is the usage of php mysql_fetch_row

What is the usage of php mysql_fetch_row

青灯夜游
青灯夜游Original
2022-04-14 13:31:512750browse

php The mysql_fetch_row() function is used to get a row from the result set as a numeric array, the syntax is "mysql_fetch_row(data)". This function retrieves a row of data from the result set associated with the result identifier data and returns it as an array, with each result column stored in an array cell.

What is the usage of php mysql_fetch_row

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

PHP mysql_fetch_row() function gets a row from the result set as an array of numbers.

Syntax

mysql_fetch_row(data)

Parameter description:

data: The data pointer to be used, required parameter, cannot be omitted. The data pointer is the result returned from mysql_query().

Description:

mysql_fetch_row() function returns an array generated based on the rows obtained, and returns false if there are no more rows.

mysql_fetch_row() Gets a row of data from the result set associated with the specified result identifier and returns it as an array. Each result column is stored in a cell of the array, starting at offset 0.

Calling mysql_fetch_row() in sequence will return the next row in the result set, or false if there are no more rows.

Example 1,

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die(&#39;Could not connect: &#39; . mysql_error());
  }

$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from Person WHERE Lastname=&#39;Adams&#39;";
$result = mysql_query($sql,$con);
print_r(mysql_fetch_row($result));

mysql_close($con);
?>

What is the usage of php mysql_fetch_row

Example 2:

What is the usage of php mysql_fetch_row

##mysql_fetch_row () obtains the data information of the current row and automatically slides to the next row after being referenced. In this example, the reference to it in line 12 is:

What is the usage of php mysql_fetch_row

#In this loop, each time mysql_fetch_row() obtains the current row data and assigns it to the array $row , and then automatically slide to the next row; after taking out the last row, the function will return false and the loop ends. In this way, all the data in the result set can be taken out row by row and displayed.

Note

The subscripts of the result array returned by mysql_fetch_row() correspond to the values ​​​​on different attributes, and the values ​​​​on the attributes can only be obtained through the subscript method, and cannot use the attribute name method. It can easily cause confusion in practical applications, so it must be used carefully. At the same time, care should be taken not to use out-of-bounds subscripts during use.

The results of the correct running of the example are as follows.

What is the usage of php mysql_fetch_row

Recommended study: "

PHP Video Tutorial"

The above is the detailed content of What is the usage of php mysql_fetch_row. For more information, please follow other related articles on the PHP Chinese website!

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