$result = $db->query('select * from table limit 1'); $fields = array_keys($result->fetch(PDO::FETCH_ASSOC)); And you will get the column names as an array in the var $fields. Usage Example: $columns = getColumns('name_of_table'); // OR getColumns($name_of_table); if you are using variable.