Search code examples
phpsqlsingle-quotes

Does putting '' on SQL column names run from a PHP program have any effect?


Is there any difference between the following two codes? Does putting '' around the column names have any effect in SQL run from a PHP program ?

Code 1: SELECT f.id FROM sample_table f;

Code 2: SELECT f.'id' FROM sample_table f;


Solution

  • From the question I will imply that you are referring to SQL dialect where the single quote is a identifier escape character.

    If that is the case, difference between them is that it is possible (but not recommended) to use reserved keywords as identifier names. For example:

    will result in error: SELECT f.where FROM sample_table f;

    works as expected: SELECT f.'where' FROM sample_table f;