php pdo:获取表的列名
如何使用PDO从表中获取所有列名?
id name age
1 Alan 35
2 Alex 52
3 Amy 15
我想得到的信息是,
id name age
编辑:
这是我的尝试,
$db = $connection->get_connection();
$select = $db->query('SELECT * FROM contacts');
$total_column = $select->columnCount();
var_dump($total_column);
for ($counter = 0; $counter < $total_column; $counter ++) {
$meta = $select->getColumnMeta($counter);
$column[] = $meta['name'];
}
print_r($column);
然后我得到,
Array
(
[0] => id
[1] => name
[2] => age
...
)