I'm fairly new to using PDO, and I'm attempting to migrate some of my websites from mysql\_\* to it.

I have formed the following:

```
if ($userData) {
    $query = "SELECT * FROM table WHERE user_id = " . $db->quote($userData['id']);
    $result = $db->query($query);

    if ($result) {
        while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
            if ($result->rowCount > 1) {
                $sql = "DELETE FROM tokens WHERE `user_id` = " . $db->quote($userData['id']) . "' AND `id` != '" . $row['id'];
                $stmt = $db->prepare($sql);
                $stmt->execute();
            }
        }

        if (!$row) {
            $sql = "INSERT INTO  tokens SET `user_id` = " . $db->quote($userData['id']) . "', `name` = '" . $db->quote($userData['name']) . "',`access_token` = '" . $db->quote($token) . "',`alive` ='Y'";
            $stmt = $db->prepare($sql);
            $stmt->execute();
        } else {
            $sql = "UPDATE tokens SET `access_token` = " . $db->quote($token) . "' WHERE `id` = " . $row['id'] . "";
            $stmt = $db->prepare($sql);
            $stmt->execute();
        }
    }
}

```

`$userData` is a Facebook API variable.

The snippet above looks fine to me, but when I run through it on a live website, the information isn't added to the database.

How would I fix this? Any assistance would be greatly appreciated.