dourui7186 2016-11-10 14:23
浏览 57
已采纳

Pdo更新不应该返回false

I have the following PHP snippet which should return false when the WHERE clause doesn't match. For ex: I don't have any selector value with ghddd in the database so it is supposed that the update shouldn't take place and I should get Failure but I keep getting Success. Where am I doing wrong?

if(isset($_COOKIE['authUser'])) {
        $cookie_contents = $_COOKIE['authUser'];
        //list($selector, $plain_token) = explode(':', $cookie_contents);
        $selector = "ghddd";
        //Empty the values
        $query = $dbh->prepare("UPDATE auth_tokens SET token=:token, expires=:expires WHERE selector = '".$selector."'");
        if($query->execute(array(
            ":token" => "",
            ":expires" => ""
        ))) {
            echo 'Success';
        }
        else {
            echo 'Failure';
        }
        // Delete the authentication cookie
        //setcookie('authUser', "", time() - 1);
    }
  • 写回答

2条回答 默认 最新

  • dragon321723 2016-11-10 15:00
    关注

    If you want check if your UPDATE query has actually updated one or more rows, you can use PDOStatement::rowCount after the execution of the query.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败