与pdo foreach的php错误

I give me this error that i dont have seen: 'Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\sito\personalImage.php on line 17' this is my code:

try{
    $conn= new PDO("mysql:host=localhost;dbname=first","root","..");
    echo "connection good";
    $user=$_COOKIE['log'];
    $conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    foreach($conn->exec('SELECT cognome FROM utenti') as $row){

    }

    $conn=null;
}
catch(PDOException $e){
    echo $e->getMessage();
}

connection to the database is good. Someone can give me an explanation

test the number of result with mysql_num_rows and then get your result.

Also 2 things very important:

  1. replace your ' by " and your " by ', because a variable can only be interpreted inside a string if this string is delimited by " (french speaker,dont know the name, please corrector replace all this blabla by the real name, thanks :) )
  2. mysql_ functions are deprecated you should no more use it, use mysqli or pdo instead (i recommend pdo).

there are both very important!

buona fortuna amico mio