Home  >  Article  >  Backend Development  >  Appropriate application of functions to implement PHP to obtain table field names_PHP tutorial

Appropriate application of functions to implement PHP to obtain table field names_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:35:111170browse

When using

PHP to obtain the table field name is implemented through the mysql_field_name() function. The syntax format of this function is as follows:

string mysql_field_name ( resource $result, int $field_offset )

mysql_field_name() function will return the name of the field at the specified index. Its parameters are described as follows.

l result: the result set returned after the mysql_query() function is executed.

l field_offset: The offset of the field, starting from zero.

The sample code for PHP to get the table field name using the mysql_field_name() function is as follows:

  1. < ?php
  2. $connection= mysql_connect("localhost",
    "root","root") or die("Failed to connect to server");
  3. mysql_select_db("sunyang",$connection)
    or die("Failed to select database");
  4. $query="select * from employee";
  5. $ result=mysql_query($query) or
    die(" Failed to query user");
  6. echo mysql_field_name($result,0);
    //Output the first field name
  7. echo "<br>";
  8. echo mysql_field_name($result,1);
    //Output the second field name
  9. mysql_close($connection);
  10. ?>

Get it in PHP above The first field name and the second field name can be output in the table field name code.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445930.htmlTechArticleUsing PHP to obtain the table field name is implemented through the mysql_field_name() function. The syntax format of this function is as follows: string mysql_field_name ( resource $result, int $field_offset ) mysql_fie...
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