转义表名MySQL [英] Escape table name MySQL
问题描述
我对转义表名有一点问题.我是如此愚蠢,以至于我选择"show"作为表名.当我使用mysqli连接时,转义可以正常工作,但不适用于经典mysql连接.有什么建议吗? 对不起,我的英语不是母语.
I have a little problem with escaping table name. I was so stupid that i choose "show" for the name of table. When I use mysqli connection the escaping works fine, but its not working with classical mysql connection. Any advise? Sorry for my English, I am not native speaker.
SELECT SQL_CALC_FOUND_ROWS year, nameShow
FROM `show`
LIMIT 0, 10
我收到错误消息
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'show' at line 2 –
查询
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS year, nameShow
FROM `show`
$sWhere
$sOrder
$sLimit
";
推荐答案
Section 9.3 of MySQL 5.1 Reference Manual says back ticks (`) or double quotes ("), however, I'd go with Fahim Parkar's comment above and just rename the table.
同样值得注意的是,如果每个第9.2节:
Also worth noting, you must use ANSI_QUOTES SQL mode if using double quotes per Section 9.2:
如果启用了ANSI_QUOTES SQL模式,则也可以 双引号内的引号标识符
If the ANSI_QUOTES SQL mode is enabled, it is also permissible to quote identifiers within double quotation marks
这篇关于转义表名MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!