Current Location: Home> Function Categories> mysql_fetch_row

mysql_fetch_row

Get a row from the result set as an array of numbers.
Name:mysql_fetch_row
Category:Uncategorized
Programming Language:php
One-line Description:Return a row in the result set as an array, and the index of the array starts at 0

Function name: mysql_fetch_row()

Applicable version: PHP 4, PHP 5 Usage: mysql_fetch_row ( resource $result ) : array|false

Description: The mysql_fetch_row() function returns a row in the result set as an array, and the index of the array starts at 0. This function can only be used to obtain the result set of SELECT statements.

parameter:

  • $result: Required. A valid MySQL result resource.

Return value:

  • If successful, a index array containing one row of data in the result set is returned, and false if there are no more rows.
  • If there are no rows in the result set, false is returned.

Example: The following example demonstrates how to use the mysql_fetch_row() function to get row data in the result set:

 // 连接到数据库$connection = mysql_connect("localhost", "username", "password"); if (!$connection) { die("数据库连接失败:" . mysql_error()); } // 选择数据库$db_select = mysql_select_db("database_name", $connection); if (!$db_select) { die("数据库选择失败:" . mysql_error()); } // 执行查询$query = "SELECT * FROM table_name"; $result = mysql_query($query, $connection); if (!$result) { die("查询失败:" . mysql_error()); } // 获取结果集中的行数据while ($row = mysql_fetch_row($result)) { // 输出行数据echo "ID: " . $row[0] . ", Name: " . $row[1] . ", Age: " . $row[2] . "<br>"; } // 释放结果集mysql_free_result($result); // 关闭数据库连接mysql_close($connection);

Notice:

  • The mysql_fetch_row() function has been deprecated and is not recommended for use in new code. It is recommended to use mysqli or PDO extensions to operate the database.
Similar Functions
Popular Articles