0

I have a problem when I execute this query:

SELECT 'preg', 'respA', 'respB', 'respC', 'respD', 'respV', 'subTema' 
FROM comun 
WHERE 'id' = 3

In the table id is of type INT.

PHPMyAdmin says that the query is correct but returns 0 rows and the table has 4 rows. What is the error?

Thank you very much!

Andrius Naruševičius
  • 8,348
  • 7
  • 49
  • 78
wiki
  • 299
  • 4
  • 16

1 Answers1

2

Use backticks to escape column and table names, not quotes.

SELECT `preg`, ...
FROM `comun` 
WHERE `id` = 3

Quotes indicate a static string. And it returns zero rows because the static string id is not equal to 3.

But actually you only need to escape reserved words in MySQL.

juergen d
  • 201,996
  • 37
  • 293
  • 362