I need to replace all double quotes to single quotes using mysql query.
我需要使用mysql查询将所有双引号替换为单引号。
How can I do that. My sql should be in double quotes.
我怎样才能做到这一点。我的sql应该是双引号。
mysql="select replace(text,'\"',''') from mytable"
throwing error. How can I escape that single quotes inside query?
投掷错误。如何在查询中转义单引号?
2 个解决方案
#1
10
Try this one
试试这个
$mysql="select replace(text,'\"',\"'\") from mytable";
Then the query will become
然后查询将成为
select replace(text,'"',"'") from mytable
at the Mysql end.
在Mysql结束。
#2
3
You need to escape the single quote '
too (see table 8.1):
你也需要逃避单引号(见表8.1):
mysql="select replace(text,'\"','\\'') from mytable"
Thus, the string sent to MySQL will read:
因此,发送到MySQL的字符串将读取:
select replace(text,'"','\'') from mytable
#1
10
Try this one
试试这个
$mysql="select replace(text,'\"',\"'\") from mytable";
Then the query will become
然后查询将成为
select replace(text,'"',"'") from mytable
at the Mysql end.
在Mysql结束。
#2
3
You need to escape the single quote '
too (see table 8.1):
你也需要逃避单引号(见表8.1):
mysql="select replace(text,'\"','\\'') from mytable"
Thus, the string sent to MySQL will read:
因此,发送到MySQL的字符串将读取:
select replace(text,'"','\'') from mytable