简体   繁体   中英

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.

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. Although the try catch block isn't giving any errors.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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