How can one retrieve the name of a specific column, such as the third column, in PDO or mysqli?

To retrieve the name of a specific column, such as the third column, in PDO or mysqli, you can use the `fetch_field_direct` method in PDO or `fetch_field` method in mysqli. These methods allow you to retrieve information about a specific column, including its name. You can then access the column name using the `name` property of the returned object.

// Using PDO
$stmt = $pdo->query("SELECT * FROM your_table");
$column = $stmt->getColumnMeta(2)['name'];
echo $column;

// Using mysqli
$result = $mysqli->query("SELECT * FROM your_table");
$column = $result->fetch_field_direct(2)->name;
echo $column;