Skip to main content
Participating Frequently
August 16, 2010
Answered

Quote phenomenon in Recordset SQL

  • August 16, 2010
  • 1 reply
  • 467 views

Why I try this in one database and it doesn't work:

$query_Recordset1 = sprintf("SELECT * FROM change WHERE change.Changes_made LIKE %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"));

but why i put quotes then it works

$query_Recordset1 = sprintf("SELECT * FROM `change` WHERE `Changes_made` LIKE %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"));

I tried this on another database and the query works without the quote. Can anyone explain this strange phenomenon?

This topic has been closed for replies.
Correct answer bregent

'Change' is a MySQL reserved words and therefore must be 'quoted'.


1 reply

bregentCorrect answer
Participating Frequently
August 16, 2010

'Change' is a MySQL reserved words and therefore must be 'quoted'.


Jun_yuanAuthor
Participating Frequently
August 17, 2010

Thanks, I will be sure to avoid the reserved word, or else I will have the trouble of putting lots of quotes.

The link to the SQL 5.1 reserved words is shown below:

http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

Jun_yuanAuthor
Participating Frequently
August 17, 2010

So far this is what I found out:

You will only put ` `(the character found below the escape key) on fields containing SQL reserved words. This applies to SELECT,DELETE,UPDATE commands.

For parameters(containing reserved words) passed using the GET,POST method, no need to put the ` `.