Describes how to obtain field attributes in PHP.

Source: Internet
Author: User

Database-related operations are always encountered during WEB development. As a beginner, this must be mastered. The following is a detailed analysis.

In addition to the field name, data type, and length, a field also has some other attributes, such as whether it is a primary key, whether it is a foreign key, and whether it is allowed to be empty. PHP can use the mysql_field_flags () function to obtain field attributes. The syntax format of this function is as follows:

String mysql_field_flags (resource $ result, int $ field_offset)

The parameters involved in the preceding syntax are described as follows:

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

L field_offset: the offset of a field. The start value is zero.

Sample Code for retrieving field attributes using PHP of mysql_field_flags () function is as follows:

 
  1. <? Php
  2. $ Connection = mysql_connect ("localhost ",
    "Root", "root") or die ("failed to connect to the 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 data"); // execute the query
  6. Echo mysql_field_flags ($ result, 0 );
    // Attributes of the first field
  7. Echo "<br> ";
  8. Echo mysql_field_flags ($ result, 1 );
    // Attributes of the Second Field
  9. Echo "<br> ";
  10. Echo mysql_field_flags ($ result, 2 );
    // Attributes of the Third Field
  11. Mysql_free_result ($ result );
  12. Mysql_close ();
  13. ?>

The above is the related PHP skills for getting field attributes.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.