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

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) ""
  }
}

你可能感兴趣的:(mysql数据库增删改查)