-1

I am using following code to save time. I have tried updating my column type to DATETIME and TIMESTAMP

$statement = $conn->prepare('UPDATE users SET update = :update WHERE id = :clientId');
                $statement->bindParam(':clientId', $clientId, PDO::PARAM_STR);
                $statement->bindParam(':update', time(), PDO::PARAM_STR);
                $statement->execute();


{"error":"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update = '1367692928' WHERE id = 'I9pm90r-b4'' at line 1"}

1 Answer 1

0

update is a Reserved Keyword and happens to be the name of your column. In order to avoid syntax error, the column name should be escaped using backticks. Ex,

UPDATE users SET `update` = :update WHERE id = :clientId

If you have the privilege to alter the table, change the column name that is not on the Reserved Keyword List to prevent the same error from getting back again on the future.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.