是否有办法为php mysqli返回字段类型和长度。我知道mysqli_result::fetch_fields
可以返回像INT
一样的字段类型,但不能返回设置为的长度。
INT(11)
我想得到"11"不是最长的字段记录,目前在表中
当我运行DESCRIBE table_name
时,我得到了我想要的信息。
Field_type(LENGTH)
INT(11)
我不懂PHP,但我认为我在评论中提出的建议会对您有所帮助:
使用describe yourTable
来获取字段列表,结果也会给你每个字段的数据类型
为什么不试试查询DESCRIBE
呢?
$link = new mysqli('localhost', 'username', 'password', 'database');
$query = mysqli_query($link, 'DESCRIBE `your_table_name`');
$desired_column = 'id';
$id = null;
while($result = $query->fetch_assoc()) {
if($result['Field'] == $desired_column) {
$field_type = $result['Type'];
preg_match('#((.*?))#', $field_type, $match);
$id = $match[1];
}
}
echo $id; // 11