mysql==》查看表字段信息的4种方法

本文介绍了在MySQL中获取表字段信息的四种实用方法:通过information_schema.columns查询,使用show create table命令,展示全字段信息以及使用desc进行描述。其中,作者通常偏好使用show create table命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

select * from information_schema.columns where table_name='tp_power';
show create table tp_power;
show full fields from tp_power;

desc tp_power;

####(以上四种都有效,我一般使用第二种);

$re=mysql_query("show create table tp_wxtoken",$conn); 

 while ($row = mysql_fetch_assoc($re)) {

       $arr[]=$row;

 }

dump($arr);

array(1) {
  [0] => array(2) {
    ["Table"] => string(10) "tp_wxtoken"
    ["Create Table"] => string(371) "CREATE TABLE `tp_wxtoken` (
  `id` int(4) NOT NULL AUTO_INCREMENT,
  `appid` varchar(100) DEFAULT NULL,
  `secret` varchar(100) DEFAULT NULL,
  `access_token` varchar(512) DEFAULT NULL,
  `expires_in` int(10) DEFAULT '0',
  `ticket` varchar(512) DEFAULT NULL,
  `ticket_time` int(10) DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8"
  }
}
$re=mysql_query("show full fields from tp_wxtoken",$conn); //等价下面的
$re=mysql_query("desc tp_wxtoken",$conn); 
while ($row = mysql_fetch_assoc($re)) {
      $arr1[]=$row;
}

dump($arr1);

array(7) {
  [0] => array(6) {
    ["Field"] => string(2) "id"
    ["Type"] => string(6) "int(4)"
    ["Null"] => string(2) "NO"
    ["Key"] => string(3) "PRI"
    ["Default"] => NULL
    ["Extra"] => string(14) "auto_increment"
  }
  [1] => array(6) {
    ["Field"] => string(5) "appid"
    ["Type"] => string(12) "varchar(100)"
    ["Null"] => string(3) "YES"
    ["Key"] => string(0) ""
    ["Default"] => NULL
    ["Extra"] => string(0) ""
  }
  [2] => array(6) {
    ["Field"] => string(6) "secret"
    ["Type"] => string(12) "varchar(100)"
    ["Null"] => string(3) "YES"
    ["Key"] => string(0) ""
    ["Default"] => NULL
    ["Extra"] => string(0) ""
  }
  [3] => array(6) {
    ["Field"] => string(12) "access_token"
    ["Type"] => string(12) "varchar(512)"
    ["Null"] => string(3) "YES"
    ["Key"] => string(0) ""
    ["Default"] => NULL
    ["Extra"] => string(0) ""
  }
  [4] => array(6) {
    ["Field"] => string(10) "expires_in"
    ["Type"] => string(7) "int(10)"
    ["Null"] => string(3) "YES"
    ["Key"] => string(0) ""
    ["Default"] => string(1) "0"
    ["Extra"] => string(0) ""
  }
  [5] => array(6) {
    ["Field"] => string(6) "ticket"
    ["Type"] => string(12) "varchar(512)"
    ["Null"] => string(3) "YES"
    ["Key"] => string(0) ""
    ["Default"] => NULL
    ["Extra"] => string(0) ""
  }
  [6] => array(6) {
    ["Field"] => string(11) "ticket_time"
    ["Type"] => string(7) "int(10)"
    ["Null"] => string(3) "YES"
    ["Key"] => string(0) ""
    ["Default"] => string(1) "0"
    ["Extra"] => string(0) ""
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值