设置if else语句PDO

How do I set the IF ELSE condition in PDO?

I want to be able to echo the results if there are records with faced = 'N'. OR echo 'Empty'.

$query = $db->prepare('SELECT student, subject FROM my_db WHERE faced = ? ORDER BY RAND() LIMIT 1');
$array = array('N');
$query->execute($array);
if ($query>0){
$result = $query->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);
} else {
    echo 'Empty';
}

You could just execute the fetch before the check:

$query->execute($array);
$result = $query->fetchAll(PDO::FETCH_ASSOC);
if (count($result) > 0){
    var_dump($result);
} else {
    echo 'Empty';
}

Here ya go! do it through the query:

SELECT 
Student,
Subject,
Max(CASE When faced ='N' then faced else 'Empty' End) as Faced
FROM my_db 
group by student