返回PHP和MySQL中受影响的行数

时间:2012-12-06 17:19:33

标签: php mysql pdo

  

可能重复:
  PHP PDO - Num Rows

我无法在PHP和MySQL中返回受影响的行数:

$sql = "SELECT `id` FROM `bookmark` WHERE `userid` = :userid AND `hash` = :hash";
    $sql_do = $db->prepare($sql);
    $sql_do->bindParam(':userid', $userid, PDO::PARAM_INT);
    $sql_do->bindParam(':hash', $hash, PDO::PARAM_STR);
    $sql_do->execute();
    $number = $db->query("SELECT FOUND_ROWS()")->fetchColumn();

返回0.

1 个答案:

答案 0 :(得分:0)

您可以在删除或更新时使用它

echo 'I have deleted ' . $db->affectedRows() . ' users';

echo mysql_affected_rows();