首先,查询mysql/ target=_blank class=infotextkey>mysql数据库/表相关信息的sql语句:
由上述SQL语句可以看到,可以使用SHOW FULL COLUMNS来列出字段及详情信息。
例子:
打印结果:
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] => 建议存储:标题、姓名等信息 [Comment] => 建议存储:标题、姓名等信息 )
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] => )
…………
补充:
当然也可以通过mysql_list_fields — 列出 MySQL 结果中的字段。
mysql_list_fields() 取得给定表名的信息,参数是数据库名和表名,返回一个结果指针。
但是,mysql_list_fields() 函数已过时。
最好用 mysql_query() 来发出一条
的 SQL 语句来代替。