i want to run a find and replace query in my sql database using php my admin. The problem is that in the text that i want to find and replace are some " characters and this causes problems when i run the command...
我想使用php my admin在sql数据库中运行查找和替换查询。问题是,在我想要查找和替换的文本中有一些“字符,当我运行命令时,这会导致问题……”
i want to search for align="right">
and replace it by align="left">
我要搜索align="right">并用align="left">替换它
i did run this command but its not working:
我确实运行了这个命令,但它不起作用:
UPDATE `ps_product_lang` SET `description` = replace(`description`,"align="right">","align="left">");
So im wondering how should this query look like as there are " characters? How is it possible to search for even much longer text and replace it using sql queries?
所以我在想,既然有“字符”,这个查询应该是什么样的呢?如何能够搜索更长的文本并使用sql查询替换它呢?
many thanks
非常感谢
1 个解决方案
#1
3
The replacement strings should be single-quoted as string literals:
替换的字符串应该是单引号的字符串文字:
UPDATE `ps_product_lang` SET `description` = replace(`description`, 'align="right">', 'align="left">');
Note that this solution is only useful if you are certain that all the strings in your description
column are exactly align="right">
. You will need to do additional work if, for example, you have some single-quoted attributes like align='right'>
in addition to the double-quoted attribute as above.
请注意,如果您确信描述列中的所有字符串都是正确的,那么这个解决方案是非常有用的。例如,除了上面所示的双引号属性之外,您还需要做一些额外的工作,比如,您有一些单引号的属性,比如align='right'>。
Also, if this is HTML markup you are performing replacements on, it is entirely possible that the closing >
won't occur right after the align
attribute. In that case, you would really need to load each row into an HTML parser to change the attribute.
另外,如果这是您正在执行的替换的HTML标记,那么关闭的>完全有可能不会发生在align属性之后。在这种情况下,您确实需要将每一行加载到HTML解析器中,以更改属性。
#1
3
The replacement strings should be single-quoted as string literals:
替换的字符串应该是单引号的字符串文字:
UPDATE `ps_product_lang` SET `description` = replace(`description`, 'align="right">', 'align="left">');
Note that this solution is only useful if you are certain that all the strings in your description
column are exactly align="right">
. You will need to do additional work if, for example, you have some single-quoted attributes like align='right'>
in addition to the double-quoted attribute as above.
请注意,如果您确信描述列中的所有字符串都是正确的,那么这个解决方案是非常有用的。例如,除了上面所示的双引号属性之外,您还需要做一些额外的工作,比如,您有一些单引号的属性,比如align='right'>。
Also, if this is HTML markup you are performing replacements on, it is entirely possible that the closing >
won't occur right after the align
attribute. In that case, you would really need to load each row into an HTML parser to change the attribute.
另外,如果这是您正在执行的替换的HTML标记,那么关闭的>完全有可能不会发生在align属性之后。在这种情况下,您确实需要将每一行加载到HTML解析器中,以更改属性。