Sunday, 20 August 2017

sql - MySQL Syntax with DELETE FROM?



I have this bit of SQL that always returns an error, though I can't find why it is returning the error. I have connected to the database with no errors. I'm running PHP 5.2.17, MySQL 5.5.25a, and Apache 2.4.2.



The SQL:




DELETE FROM mail WHERE to=1


The error:




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 'to=1' at line 1




Answer



TO is a reserved word, you need to use backticks:



 DELETE FROM mail WHERE `to` = 1

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...