PHP获取数据表字段名到数组,获取Mysql字段属性.
<?php
$sql = "SHOW COLUMNS FROM `counter`";
if($res = mysql_query($sql)){
while($column = mysql_fetch_assoc($res)){
$columns[] = $column;
//$fields = $column['Field'];//将数据表名称返回到数组中.
}
}
foreach($columns as $column){//
echo <<<EOT
<p>
<div>字段名:{$column['Field']}</div>
<div>类型:{$column['Type']}</div>
<div>空值:{$column['Null']}</div>
<div>主键:{$column['Key']}</div>
<div>默认值:{$column['Default']}</div>
<div>其他属性:{$column['Extra']}</div>
</p>
EOT;
}
?> |
|