简体   繁体   English

PDO UPDATE不更新数据库

[英]PDO UPDATE not updating the database

My update statement dosn't seem to be updating my database but I'm unsure why, I've used the same code elsewhere in my script and it works fine. 我的更新声明似乎没有更新我的数据库,但我不确定为什么,我在我的脚本中的其他地方使用了相同的代码,它工作正常。

try
{
    // update the live documents details
    $sth = $conn->prepare("UPDATE docs SET ref = :ref, rev = :rev, updated = :updated WHERE id = :id");
    $sth->bindParam(':ref', $ref);
    $sth->bindParam(':rev', $rev);
    $sth->bindParam(':updated', $date);
    $sth->bindParam(':id', $currentid);
    $sth->execute();
}
catch(Exception $e)
{
    throw new Your_Exception($e->getMessage());
    // or
    throw $e;
}

I've tried manually inputting a query into the database using PHPMyAdmin just to test I have my table names correct and the query does work as expected. 我尝试使用PHPMyAdmin手动输入查询到数据库只是为了测试我的表名是否正确,查询是否按预期工作。

UPDATE docs SET ref =  'FMS',
rev =  'D',
updated = NOW( ) WHERE id =73

So this leaves me thinking I have an error in my PDO statement. 所以这让我觉得我的PDO语句中有错误。 Although the try catch block isn't giving any errors. 虽然try catch块没有给出任何错误。

There are all possible reasons 有可能的原因

  • there is an error in the query (which have to be thrown) 查询中有错误(必须抛出)
  • there is no data to match the criteria. 没有数据符合标准。
  • the data is already updated - nothing to change. 数据已经更新 - 无需更改。
  • you are checking not the table/database which you were updating. 您正在检查您正在更新的表/数据库。

Please verify all the issues listed. 请验证列出的所有问题。

By the way, to be able to see thrown errors you have to configure PHP properly 顺便说一下,为了能够看到抛出的错误,你必须正确配置PHP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM