PDO :: FETCH_ASSOC问题

时间:2019-05-04 10:05:10

标签: php sql pdo

所以,我有这段代码可以更新数据库中的值,但是它不起作用,有人可以帮助我找出原因吗?

$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();```

1 个答案:

答案 0 :(得分:0)

也许会改变

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

$try = $conn->rowCount();

是否检测更新记录。