第1个回答 推荐于2017-12-16
<?php
$mysqli = new mysqli("localhost","user","password","database");
$sql = "describe table";
$re=$mysqli->query($sql);
while( $row=$re->fetch_array()){
if($row['Key']=='PRI'){
ECHO $row['Field']."是这个表的主键。";
break;
}
}
?>
数组里[key]=>PRI 的 就是主键
[Extra] => auto_increment 是自增字段本回答被提问者采纳
第2个回答 2008-12-08
在创建表的sql语句中 'primary key' 是指主键。有这样属性的字段是自动增加值的。
第3个回答 推荐于2016-09-16
$con = mysql_connect('localhost','root','');
if($con){
mysql_query('use yatibang');
mysql_query('set names utf8');
}else{
echo "数据连接失败";
}
$sql = "desc app_category";
$res = mysql_query($sql);
$row = $rows = array();
while( $row = mysql_fetch_assoc($res)){
if($row['Key'] == 'PRI'){
$rows['PRI'] = $row['Field']; //主键
$rows['extra'] = $row['Extra']; //自增
}
}
var_dump($rows);
第4个回答 2008-12-08
这个怎么能肯定这个表有主键呢
多数表中没有主键或自增字段