Current Location: Home> Function Categories> mysql_field_name

mysql_field_name

Gets the field name of the specified field in the result.
Name:mysql_field_name
Category:Uncategorized
Programming Language:php
One-line Description:Get the name of the specified field

Function name: mysql_field_name()

Applicable version: PHP 4, PHP 5

Usage: The mysql_field_name() function is used to get the name of the specified field.

Syntax: string mysql_field_name ( resource $result , int $field_offset )

parameter:

  • result: MySQL query result resource, and the result returned by the mysql_query() function.
  • field_offset: The offset of the field, counting from 0.

Return value: Returns the name of the specified field, and returns FALSE if an error occurs.

Example:

 <?php // 建立MySQL 连接$link = mysql_connect("localhost", "username", "password"); if (!$link) { die('连接失败:' . mysql_error()); } // 选择数据库$db_selected = mysql_select_db("database_name", $link); if (!$db_selected) { die('无法使用数据库:' . mysql_error()); } // 执行查询$result = mysql_query("SELECT * FROM table_name", $link); if (!$result) { die('查询失败:' . mysql_error()); } // 获取第一个字段的名称$field_name = mysql_field_name($result, 0); echo "第一个字段的名称是:" . $field_name; // 关闭连接mysql_close($link); ?>

In the above example, we first establish a connection to the MySQL database and select the specified database. We then execute a query and save the query results in the $result variable. Next, use mysql_field_name() function to get the name of the first field in the query result and print it out. Finally, the connection to the database is closed.

Please note that mysql_field_name() function has been deprecated in PHP 7, and it is recommended to use the mysqli or PDO extension instead.

Similar Functions
Popular Articles