doudou3935 2017-02-12 18:43
浏览 29
已采纳

无效的sql语句 - 撇号? [重复]

This question already has an answer here:

i programm some PHP Scripts and i wrote this sql query (for example):

INSERT INTO \`table1\` (\`article\`, \`typ\`)
    VALUES(\`test\`, \`test2\`)

this query works.

my problem is that if i write the tablename and columns like this 'table1' i get an sql error: SQL Error(1064): You have an error in your SQL Syntax; check the manual that corresponds to your MariaDB server Version for the right syntax to use near ''article', 'typ') VALUES('test', 'test1')'

Does anybody know why i have to write it like this `table1` and why it doesnt work with normal --> ' ?

Server-Typ: MariaDB

Server-Version: 10.1.9-MariaDB - mariadb.org binary distribution

Server-Zeichensatz: UTF-8 Unicode (utf8)

</div>
  • 写回答

1条回答 默认 最新

  • douqiang7462 2017-02-12 18:47
    关注

    This is too long for a comment. The right way to write the code is:

    INSERT INTO table1(article, typ)
        VALUES ('test', 'test2')
    

    All of the identifiers (table and column names) are valid names. They do not need to be escaped. Hence, no backticks are necessary.

    You do need single quotes for quoted strings, not backticks. If the backticks are part of the name, you could just do:

    INSERT INTO table1(article, typ)
        VALUES ('`test`', '`test2`');
    

    But that seems highly unlikely.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题