I am trying to make a MySQL query with keywords in it. Is there any way to encapsulate these keywords so that I can use them anyway?
Here's the query that won't execute:
INSERT INTO PendingPasswordRecovery (key, userID, TimeModified, TimeCreated, TimeDeleted, IsDeleted) VALUES ('test123', 1, '2011-07-26 16:26:56', '2011-07-26 16:26:56', '1000-01-01 00:00:00', false)
As you have probably guessed already, "key" is the keyword that I am using in the query, and it is unfortunately also the name of the column I want to use.
解决方案
Use backticks:
INSERT INTO PendingPasswordRecovery (`key`, `userID`, `TimeModified`, `TimeCreated`, `TimeDeleted`, `IsDeleted`) VALUES ('test123', 1, '2011-07-26 16:26:56', '2011-07-26 16:26:56', '1000-01-01 00:00:00', false)
I have added backticks to all column names but you could just do it for the keyword. The backticks are called "identifier quote characters". For more information, see: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html and http://dev.mysql.com/doc/refman/5.1/en/identifiers.html