日期:2014-05-17 浏览次数:20562 次
$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());
}