mysql==テーブルフィールド情報を表示する4つの方法
3503 ワード
select * from information_schema.columns where table_name='tp_power';show create table tp_power;show full fields from tp_power;
desc tp_power;
####(以上の4種類はすべて有効で、私は普通第2種類を使います);
$re=mysql_query("show create table tp_wxtoken",$conn);
while ($row = mysql_fetch_assoc($re)) {
$arr[]=$row; }
dump($arr);
$re=mysql_query("desc tp_wxtoken",$conn);
while ($row = mysql_fetch_assoc($re)) {
$arr1[]=$row;
}
dump($arr1);
desc tp_power;
####(以上の4種類はすべて有効で、私は普通第2種類を使います);
$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) ""
}
}