开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜