标签:
首先我们需要了解下查询MySQL数据库/表相关信息的SQL语句:
由上述SQL语句可以看到,我们可以使用SHOW FULL COLUMNS来列出字段及详情信息,示例代码:
打印结果:
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() 来发出一条 SHOW COLUMNS FROM table [LIKE ‘name‘] 的 SQL 语句来代替。详细可参考PHP帮助文档:PHP: mysql_list_fields - Manua
标签:
原文地址:http://www.cnblogs.com/love1226/p/4443167.html