mysql_fetch_row
Get a row from the result set as an array of numbers.
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:
Return value:
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: