Q:

PHP MySQL result - unnecessary use of foreach

I use this method to access my MySQL database:
$STH = $DBH->prepare("SELECT email FROM user WHERE unum = :u");
$STH->bindParam(':u', $json['u']); // Example only
try {
    $STH->execute();
    $STH->setFetchMode(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
    echo $e->getMessage();
}

Now, I know that $STH will only contain one row, but I always do this:
foreach($STH as $row){
    ... $row['email']... etc

The foreach is utterly unnecessary and makes the code harder to follow. How can I access email in $STH without using foreach?
Thanks.

A:

You can use
$row = $STH->fetch();
echo $row['email'];

It will get only 1 row.

