I have the following code:
$SQL = "UPDATE jobs
SET read = '1'
WHERE id = '$job_id'";
$STH = $DBH->prepare($SQL);
$STH->execute();
read is a field in the table with a data type of BIT. The current data inside this field is 0 (false), and I’m trying to change it to 1 (true). However, I am getting this error:
Message: 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 ‘read = ‘1’ WHERE id = ’25” at line 2
I can’t see any syntax errors, so what is the problem?
READis a reserved word in MySQL.You will need to quote it in order to use it as column name:
This is why a quote everything in every query, to avoid problems like this. Remember, quoting object names (tables, columns etc) must be done with backticks:
`