This method is supported in the MySQL 5.0+ driver. It can be used for object hydration:
<?php
$pdo_stmt = $dbh->execute('SELECT discussion.id, discussion.text, comment.id, comment.text FROM discussions LEFT JOIN comments ON comment.discussion_id = discussion.id');
foreach(range(0, $pdo_stmt->columnCount() - 1) as $column_index)
{
$meta[] = $pdo_stmt->getColumnMeta($column_index);
}
while($row = $pdo_stmt->fetch(PDO::FETCH_NUM))
{
foreach($row as $column_index => $column_value)
{
}
}
?>
If you are building an ORM, this method is very useful to support more natural SQL syntax. Most ORMs require the column names to be aliases so that they can be parsed and turned into objects that properly represent has_one, has_many, many_to_many relationships.