如何使用mysqli_fetch_fields获得自动递增的详细信息?

问题描述 投票:0回答:1

目标:使用mysqli_fetch_fields获取字段的auto_increment细节

代码:

<?php
require_once("dbc.php");
$query="SELECT id, name, age from student WHERE 1>2";
$result=mysqli_query($dbc, $query);
$metas=mysqli_fetch_fields($result);
foreach($metas as meta){
$col_name=meta->name;
$col_type=meta->type;
$col_length=meta->length;
$col_flags=meta->flags;
echo "col_name: $col_name, col_type: $col_type, col_length: $col_length, col_flags: $col_flags";
}
mysqli_close($dbc);
?>

观察:在mysql提示符下

mysql> describe student;
Field        Type        Null    Key    Default    Extra
id           int(16)     NO      PRI    NULL       auto_increment

但是在mysqli中

col_name: id, col_type: 3 , col_length: 11, col_flags: 49967

col_flags值49967对应于主键。

[请指导我使用mysqli_fetch_fields获取字段是否自动递增?

php mysqli auto-increment
1个回答
0
投票

要测试AUTO_INCREMENT的适当标志位是位9(AUTO_INCREMENT_FLAG)(Source)。像这样的东西:

$auto_increment = $col_flags & AUTO_INCREMENT_FLAG;
© www.soinside.com 2019 - 2024. All rights reserved.