找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1188|回复: 0
打印 上一主题 下一主题

php mysql获取表字段名称和字段信息的三种方法

[复制链接]

2647

主题

2647

帖子

7881

积分

论坛元老

Rank: 8Rank: 8

积分
7881
跳转到指定楼层
楼主
发表于 2018-2-14 05:30:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            php mysql获取表字段名称和字段信息的三种方法
先给出本实例中使用的表的信息:

使用desc获取表字段信息
php代码如下:
运行结果:
Array
(
  [Field] => student_id
  [Type] => int(4)
  [Null] => NO
  [Key] => PRI
  [Default] =>
  [Extra] => auto_increment
)
Array
(
  [Field] => student_name
  [Type] => varchar(50)
  [Null] => NO
  [Key] =>
  [Default] =>
  [Extra] =>
)
Array
(
  [Field] => class_id
  [Type] => int(4)
  [Null] => NO
  [Key] =>
  [Default] =>
  [Extra] =>
)
Array
(
  [Field] => total_score
  [Type] => int(4)
  [Null] => NO
  [Key] =>
  [Default] =>
  [Extra] =>
)

使用SHOW FULL FIELDS获取表字段信息
php代码如下:
运行结果:
Array
(
  [Field] => student_id
  [Type] => int(4)
  [Collation] =>
  [Null] => NO
  [Key] => PRI
  [Default] =>
  [Extra] => auto_increment
  [Privileges] => select,insert,update,references
  [Comment] =>
)
Array
(
  [Field] => student_name
  [Type] => varchar(50)
  [Collation] => latin1_swedish_ci
  [Null] => NO
  [Key] =>
  [Default] =>
  [Extra] =>
  [Privileges] => select,insert,update,references
  [Comment] =>
)
Array
(
  [Field] => class_id
  [Type] => int(4)
  [Collation] =>
  [Null] => NO
  [Key] =>
  [Default] =>
  [Extra] =>
  [Privileges] => select,insert,update,references
  [Comment] =>
)
Array
(
  [Field] => total_score
  [Type] => int(4)
  [Collation] =>
  [Null] => NO
  [Key] =>
  [Default] =>
  [Extra] =>
  [Privileges] => select,insert,update,references
  [Comment] =>
)

使用mysql_fetch_field方法获取表字段信息
php代码如下:
运行结果如下:
stdClass Object
(
  [name] => student_id
  [table] => student
  [def] =>
  [max_length] => 1
  [not_null] => 1
  [primary_key] => 1
  [multiple_key] => 0
  [unique_key] => 0
  [numeric] => 1
  [blob] => 0
  [type] => int
  [unsigned] => 0
  [zerofill] => 0
)
stdClass Object
(
  [name] => student_name
  [table] => student
  [def] =>
  [max_length] => 5
  [not_null] => 1
  [primary_key] => 0
  [multiple_key] => 0
  [unique_key] => 0
  [numeric] => 0
  [blob] => 0
  [type] => string
  [unsigned] => 0
  [zerofill] => 0
)
stdClass Object
(
  [name] => class_id
  [table] => student
  [def] =>
  [max_length] => 1
  [not_null] => 1
  [primary_key] => 0
  [multiple_key] => 0
  [unique_key] => 0
  [numeric] => 1
  [blob] => 0
  [type] => int
  [unsigned] => 0
  [zerofill] => 0
)
stdClass Object
(
  [name] => total_score
  [table] => student
  [def] =>
  [max_length] => 3
  [not_null] => 1
  [primary_key] => 0
  [multiple_key] => 0
  [unique_key] => 0
  [numeric] => 1
  [blob] => 0
  [type] => int
  [unsigned] => 0
  [zerofill] => 0
)
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
            
            
您可能感兴趣的文章:
  • php 获取mysql数据库信息代码
  • mysql 获取当天发布的信息的语句
  • MySQL中show命令方法得到表列及整个库的详细信息(精品珍藏)
  • MySQL笔记之系统信息函数详解
  • 解析MYSQL显示表信息的方法
  • PHP获取php,mysql,apche的版本信息示例代码
  • php获取mysql字段名称和其它信息的例子
  • PHP获取mysql数据表的字段名称和详细信息的方法
  • php+mysqli实现将数据库中一张表信息打印到表格里的方法
  • Sql查询MySql数据库中的表名和描述表中字段(列)信息
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端