PHP PDO不更新表且不产生错误 [英] PHP PDO Not Updating Table and Producing No Errors

查看:67
本文介绍了PHP PDO不更新表且不产生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PDO准备好的语句来更新我的一个表中的单个元素,由于某种原因,它不起作用.我正在使用try-and-catch,没有收到来自系统的错误.我也回显了我的两个绑定参数,它们都在系统中注册,所以我不知道为什么它没有通过.我在另一个脚本中使用了与此查询非常相似的查询,一切都很好.

I'm trying to update a single element in one of my tables using a PDO prepared statement, and for some reason it's not working. I'm using try-and-catch and I'm receiving no errors from the system. I've also echoed both of my bound parameters, and they are both registering in the system, so I don't know why it's not going through. I've used a query very similar to this in another script and everything was fine.

if($_POST['check_request'] == "Yes"){
    $check_amnt = $_POST['check_amnt'];
    try {
        $STH = $DBH->prepare('UPDATE accounts SET check = :check_amnt WHERE accnt = :user');
        $STH->bindParam(':check_amnt', $check_amnt);
        $STH->bindParam(':user', $ulog);
        $STH->execute();
    }
    catch(PDOException $e) {  
        echo "Check Input Error: " .$e->getMessage(). "</br>";
    }
}

推荐答案

您是否使用以下方法为PDO设置了例外模式:

Did you set the exception mode for PDO with:

$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

更新: check是mysql保留字,您需要对其进行转义.

Update: check is mysql reserved words, you need to escape it.

$STH = $DBH->prepare('UPDATE accounts SET `check` = :check_amnt WHERE accnt = :user');

这篇关于PHP PDO不更新表且不产生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆