简体   繁体   中英

How to replace all double quotes to single quotes using mysql replace?

I need to replace all double quotes to single quotes using mysql query.

How can I do that. My sql should be in double quotes.

mysql="select replace(text,'\"',''') from mytable"

throwing error. How can I escape that single quotes inside query?

Try this one

 $mysql="select replace(text,'\"',\"'\") from mytable";

Then the query will become

select replace(text,'"',"'") from mytable

at the Mysql end.

You need to escape the single quote ' too (see table 8.1 ):

mysql="select replace(text,'\"','\\'') from mytable"

Thus, the string sent to MySQL will read:

select replace(text,'"','\'') from mytable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM