如何知道SQL查询PDO是否为空


how to know if the SQL query PDO is empty?

我开始绝望,因为我没有提出条件,如果PDO请求的结果是空的。。。这是我使用的代码:

try
{
    $pdo=new PDO('mysql:host=localhost;dbname=MyDataBase','root','');
}
catch (Exception $e)
  {
    die('Erreur : ' . $e->getMessage());
  }
$sql = "SELECT COUNT(*) FROM Mytable WHERE name=".$name;
if ($res = $bdd->query($sql)){
  echo" this name exist ";
}
else {
  echo "No rows matched the query.";
}

Ues这个。。。

     $name= $_POST['name'];

        try
        {
            $pdo=new PDO('mysql:host=localhost;dbname=MyDataBase','root','');
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        }
        catch (Exception $e)
          {
            die('Erreur : ' . $e->getMessage());
          }
        $sql = "SELECT COUNT(*) FROM Mytable WHERE name=".$name;
        $res = $pdo->query($sql);
        $row = $res->fetchColumn();
        if ($row){
          echo" this name exist ";
    }
       else {
          echo "No rows matched the query.";
       }

它应该在查询语句的$bdd中使用$pdo。。。基本上是打字错误。。这就是