I want to convert my code from working with mysql to pdo. and i was looking for an equivalent function for mysql_field_name but i didn't find any, except this function PDOStatement::getColumnMeta, but PHP documentation say it's "EXPERIMENTAL" and it won't work with future release of PHP. so i did this work.
assuming i have this table
id         name        age       city
1          ad          25         a      
2          im          23         b
3          sh          21         c 
and i wanna select only the name and city
 name       city
  ad          a      
  im          b
  sh          c 
    $link = new PDO("mysql:host=localhost;dbname=db_name;charset=utf8",user,pass);
    $link->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    $link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $query="SELECT name,city FROM  table" ;
    $result = link->prepare($query);
    $result->execute();
    $result ->fetchAll(PDO::FETCH_ASSOC);
    foreach ($result as $value){
        $tablename =array_keys($value);
    }
    echo "<table><tr>";
    foreach ($tablename  as $key)
        echo "<td>".$key."</td>";
    echo "</tr></table>";
i'm not sure if this's the right way to do it. or if there's a PDO function can do this work