首页 > 数据库 >pymysql 引号转义处理方法

pymysql 引号转义处理方法

时间:2022-11-09 11:46:59浏览次数:45  
标签:string 引号 pymysql 转义 escape data your

pymysql直接插入带有双引号或单引号的字符串,报错:

pymysql.err.ProgrammingError: (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 '

 

解决方法:

使用pymysql.escape_string(str) 转义:
escape_string(record["content"])
# v1.0.0及以上
from pymysql.converters import escape_string

# v0.10.1及以下
from pymysql import escape_string
#data为含有单引号或者双引号的字符串
data = escape_string(data)

 

标签:string,引号,pymysql,转义,escape,data,your
From: https://www.cnblogs.com/meipu/p/16873108.html

相关文章