phpmyadmin sql apostrophe not working [duplicate]

2019-09-09 11:43发布

hey guys was hoping you could help me out,

Not sure if I always had this problem or if its new, in phpmyadmin in the sql tab, the apostrophe it recognizes is different from what i type, for example,

when i type, it is

SELECT * FROM 'table'

this gives me an error, so instead I have to like copy/paste the inverted commas of some prebuilt query so that it looks like

SELECT * FROM `table`

see how the apostrophes are different? any way I can fix this?

also, i have seen many queries on the web, and i think even queries i call from php dont require table names to have apostrophes. But when write it in phpmyadmin, I can do queries without table names having apostrophes?

thanks in advance.

5条回答
做个烂人
2楼-- · 2019-09-09 12:21

You should use ` in cases that your table/field name is a reserve word eg:

SELECT `distinct`, myfields FROM mytable

note that distinct is an sql command so you need to put the `.

SELECT * FROM `table`

table here should be inside `.

查看更多
疯言疯语
3楼-- · 2019-09-09 12:24

There are two different characters, the backtick and the single quote. Table and column names can be surrounded by the backtick, strings can be surrounded by quotes. There is nothign to fix :D

查看更多
来,给爷笑一个
4楼-- · 2019-09-09 12:26

You dont need apostrophe on table name.

查看更多
啃猪蹄的小仙女
5楼-- · 2019-09-09 12:32

You should only need to quote table names when they conflict with a reserved word.

Also:

` = Grave accent, or (because someone needed to invent a word) backtick
' = Apostrophe, or straight single quote
查看更多
地球回转人心会变
6楼-- · 2019-09-09 12:39

In MYSQL, table is a reserved keyword. If you want to use reserved keywords in mysql in query, you have to enclose them in backtick(`).

As table is reserved keyword you query should be

SELECT * FROM `table`

Regarding single quote ('), in mysql, it represents string value.

SELECT *, 'table' FROM `table`;

Demo

查看更多
登录 后发表回答