1
UPDATE 'module_tests' SET 'tests_content' = REPLACE('tests_content', '<a onclick=', '<a class="dic"  onclick=');

When I am tried to run top query in phpmysql it gave bellow error. Can someone tell me the reason for this?

#1064 - 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 ''module_tests' SET 'tests_content' = REPLACE('tests_content', '<a onclick=', '' at line 1
4

2 回答 2

2

table删除和名称周围的单引号。您的column查询应该是这样的:

UPDATE module_tests SET tests_content = REPLACE(tests_content, '<a onclick=', '<a class="dic"  onclick=');

查看SQLFIDDLE

我怀疑,您对单引号(')和反引号(`)有些困惑。在您的示例中,您可以使用反引号来确保您的表名和字段名称不会与 mysql 中的保留字发生冲突......使用反引号,您可以像这样修改查询:

UPDATE `module_tests` SET `tests_content` = REPLACE(`tests_content`, '<a onclick=', '<a class="dic"  onclick=');

查看带反引号的查询

于 2013-05-02T04:45:24.477 回答
0

将查询更改为:

UPDATE `module_tests` 
   SET `tests_content` = REPLACE(`tests_content`, '<a onclick=', '<a class="dic"  onclick=');

您将表和列名作为字符串传递。

于 2013-05-02T04:40:35.150 回答