How to check if a row exist in the database using PDO?

You can use the rowCount() method of the PDOStatement object to check if a row exists in the database using PDO.

Watch a course Learn object oriented PHP

Example:

$stmt = $pdo->prepare("SELECT * FROM table_name WHERE column = :value");
$stmt->execute(['value' => $value]);
if($stmt->rowCount() > 0) {
    // row exists
} else {
    // row does not exist
}

Note that rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object. For SELECT statements, some databases may return the number of rows returned, however, it's not guaranteed to work across all PDO drivers.