Reputation: 21
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...
i want to search for align="right">
and replace it by 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?
many thanks
Upvotes: 2
Views: 409
Reputation: 270767
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.
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.
Upvotes: 2