twigg
twigg

Reputation: 3993

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.

Upvotes: 0

Views: 138

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157888

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

Upvotes: 2

Related Questions