How to get the field data type in PHP

Source: Internet
Author: User

For a beginner, they must learn how to use various types of resources flexibly.

The mysql_field_type () function obtains the Data Type of a field. The syntax format of this function is as follows.

String mysql_field_type (resource $ result, int $ field_offset)

The mysql_field_type () function is similar to the mysql_field_name () function, but the mysql_field_type () function returns the Data Type of the field. 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 a field. The start value is zero.

The sample code for using the mysql_field_type () function is as follows:

Code 23-12 cd-rom codes chapter 23.3mysql _ field_type.php

 
  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 ");
  6. // Execute the query
  7. Echo mysql_field_type ($ result, 0 );
  8. // Data type of the first field
  9. Echo "<br> ";
  10. Echo mysql_field_type ($ result, 1 );
  11. // Data type of the Second Field
  12. Echo "<br> ";
  13. Echo mysql_field_type ($ result, 2 );
  14. // Data type of the Third Field
  15. Mysql_free_result ($ result );
  16. Mysql_close ();
  17. ?>

After the preceding code is executed, the Data Types of the first three fields in the table "employee" are output.


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.