How can the fetch method in PHP PDO be utilized to retrieve specific column values from a database query?

To retrieve specific column values from a database query using the fetch method in PHP PDO, you can specify the fetch mode as PDO::FETCH_COLUMN and provide the index of the column you want to retrieve.

// Assuming $pdo is your PDO connection object
$stmt = $pdo->query("SELECT column1, column2 FROM table_name");
$results = $stmt->fetch(PDO::FETCH_COLUMN, 0); // Retrieves values from column1