您可以直接检查返回值。
$stmt = $conn->prepare('SELECt * FROM table WHERe ID=?');$stmt->bindParam(1, $_GET['id'], PDO::PARAM_INT);$stmt->execute();$row = $stmt->fetch(PDO::FETCH_ASSOC);if( ! $row){ die('nothing found');}如果您询问是否进行检查 而不进行获取, 则只需让MySQL返回a
1(或使用
COUNT()命令)。
$sql = 'SELECt 1 from table WHERe id = ? LIMIT 1';//$sql = 'SELECt COUNT(*) from table WHERe param = ?'; // for checking >1 records$stmt = $conn->prepare($sql);$stmt->bindParam(1, $_GET['id'], PDO::PARAM_INT);$stmt->execute();if($stmt->fetchColumn()) die('found');


