what is correct sql statement syntax in PHP?
when I write a sql statement in php, i usualy write it as below
SELECT COUNT(*) FRO开发者_开发百科M catalogsearch_query AS main_table
but I found that some people write sql statement like
SELECT COUNT(*) FROM `catalogsearch_query` AS `main_table`
do I have to use `
?
You don't have to use backticks. However when you're using reserved keywords as table or field names, then you have to enclose them in backticks for them to work.
From MySql docs:
Database, table, index, column, and alias names are identifiers. An identifier may be quoted or unquoted. If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it.
We use the backtick ` for quoting.
精彩评论