时间:2021-07-01 10:21:17 帮助过:2人阅读
$result = mysql_query("SELECT * FROM table");
$fields = mysql_num_fields($result);
for ($i=0; $i < $fields; $i++) {
$names[] = mysql_field_name($result, $i);
}
print_r($names);
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$stmt = $dbh->query("select * from tbl_name");
for($i=0; $i<$stmt->columnCount(); $i++) {
echo $stmt->getColumnMeta($i)['name'], PHP_EOL;//php5.4适使用,之前的版本需拆成两句
}
} catch (PDOException $e) {
die("Error!: " . $e->getMessage());
}