get column name for PDO from query
<p>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.</p>

<p>assuming i have this table</p>

<pre><code>id         name        age       city
1          ad          25         a      
2          im          23         b
3          sh          21         c 
</code></pre>

<p>and i wanna select only the name and city  </p>

<pre><code> name       city
  ad          a      
  im          b
  sh          c 

    $link = new PDO("mysql:host=localhost;dbname=db_name;charset=utf8",user,pass);
    $link-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    $link-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $query="SELECT name,city FROM  table" ;
    $result = link-&gt;prepare($query);
    $result-&gt;execute();
    $result -&gt;fetchAll(PDO::FETCH_ASSOC);

    foreach ($result as $value){
        $tablename =array_keys($value);
    }

    echo "&lt;table&gt;&lt;tr&gt;";
    foreach ($tablename  as $key)
        echo "&lt;td&gt;".$key."&lt;/td&gt;";
    echo "&lt;/tr&gt;&lt;/table&gt;";
</code></pre>

<p>i'm not sure if this's the right way to do it.
or if there's a PDO function can do this work </p>