dqjjw04440
2019-05-04 10:05
浏览 101
已采纳

PDO :: FETCH_ASSOC问题[重复]

This question already has an answer here:

So, I have this code which is supposed to update a value in database but it doesn't work, can anybody help me find out why is that?

$bitcoin = $_POST['bitcoin'];

        $dsn = 'mysql:host=127.0.0.1;dbname=user_db;charset=utf8';

        $conn = new PDO($dsn, $username1, $password);
        $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        $stmt= $conn->prepare("UPDATE users SET bitcoin = :bitcoin WHERE username = :username");
        $stmt->bindParam(':bitcoin', $bitcoin,PDO::PARAM_STR);
        $stmt->bindParam(':username', $username,PDO::PARAM_STR);
        $stmt->execute();
        $try = $conn->fetch(PDO::FETCH_ASSOC);
        if ($try) {
        array_push($success, "Bitcoin Wallet Adress updated successfully.");
        } else {
        array_push($errors, "Error updating Bitcoin Wallet Adress, please report this error to us.");
        }
        header('location: settings.php');
        $conn->close();```
</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douquan1953 2019-05-04 11:56
    已采纳

    Maybe change

    $try = $conn->fetch(PDO::FETCH_ASSOC);
    

    to

    $try = $conn->rowCount();
    

    for detecting update record or not.

    点赞 评论

相关推荐 更多相似问题