Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Quote phenomenon in Recordset SQL

New Here ,
Aug 16, 2010 Aug 16, 2010

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?

TOPICS
Server side applications
469
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 16, 2010 Aug 16, 2010

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


Translate
LEGEND ,
Aug 16, 2010 Aug 16, 2010

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


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 16, 2010 Aug 16, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 16, 2010 Aug 16, 2010
LATEST

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 ` `.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines