Home > Backend Development > PHP Tutorial > Example of php getting mysql field name and other information_PHP tutorial

Example of php getting mysql field name and other information_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:32:47
Original
829 people have browsed it

First we need to understand the SQL statements for querying MySQL database/table related information:

Copy the code The code is as follows:

SHOW DATABASES                                                                                                                                                                  
SHOW TABLES [FROM db_name] //List database data tables.
SHOW CREATE TABLES tbl_name                                                                                                                                                                                                                
SHOW TABLE STATUS [FROM db_name] //List the data table and table status information.
SHOW COLUMNS FROM tbl_name [FROM db_name] //List the data table fields
SHOW FIELDS FROM tbl_name [FROM db_name], DESCRIBE tbl_name [col_name].
SHOW FULL COLUMNS FROM tbl_name [FROM db_name]//List fields and details
SHOW FULL FIELDS FROM tbl_name [FROM db_name] //List complete attributes of fields
SHOW INDEX FROM tbl_name [FROM db_name] / /List table indexes.
SHOW STATUS //List DB Server status.
SHOW VARIABLES                                                                                                                                                                
SHOW PROCESSLIST                                                                                                                                                    
Show Grants for User // List a user permissions

As can be seen from the above SQL statement, we can use Show Full Column >
Copy code The code is as follows:
$rescolumns = mysql_query("SHOW FULL COLUMNS FROM ".TB_NAME."") ;
while($row = mysql_fetch_array($rescolumns)){
// echo 'Field name: '.$row['Field'].'-Data type: '.$row['Type'].'- Comment: '.$row['Comment'];
// echo '

';
print_r($row);
}

Print results:


Copy code The code is as follows:
Array ( [0] => id [Field] => id [1] => char(2) [Type] => char(2) [2] => utf8_general_ci [Collation] => utf8_general_ci [3] => NO [Null] => NO [ 4] => PRI [Key] => PRI [5] => [Default] => [6] => [Extra] => [7] => select,insert,update,references [Privileges] => select,insert,update,references [8] => [Comment] => )
Array ( [0] => title [Field] => title [1] => char(50) [Type] => char(50) [2] => utf8_general_ci [Collation] = > utf8_general_ci [3] => YES [Null] => YES [4] => [Key] => [5] => [Default] => [6] => [Extra] => [7] => select,insert,update,references [Privileges] => select,insert,update,references [8] => Recommended storage: title, name and other information [Comment] => Recommendation Storage: title, name and other information)

Array ( [0] => des [Field] => des [1] => varchar(255) [Type] => varchar(255) [2] => utf8_general_ci [Collation] = > utf8_general_ci [3] => YES [Null] => YES [4] => [Key] => [5] => [Default] => [6] => [Extra] => [7] => select,insert,update,references [Privileges] => select,insert,update,references [8] => [Comment] => )

…………


Additional information:
Of course, you can also use mysql_list_fields — to list the fields in the MySQL results. mysql_list_fields() obtains information about a given table name. The parameters are the database name and table name, and returns a result pointer.
However, the mysql_list_fields() function is deprecated. It is better to use mysql_query() to issue a SQL statement SHOW COLUMNS FROM table [LIKE 'name'] instead. For details, please refer to the PHP help document: http://www.php.net/manual/zh/function.mysql-list-fields.php

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/754338.htmlTechArticleFirst we need to understand the SQL statements for querying MySQL database/table related information: Copy the code as follows: SHOW DATABASES/ /List MySQL Server databases. SHOW TABLES [FROM db_name...
Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template