MySQL转义字符串Python [英] Escape string Python for MySQL
问题描述
我使用Python和MySQLdb来下载网页并将其存储到数据库中。我遇到的问题是我无法在数据库中保存复杂的字符串,因为它们没有被正确的转义。
I use Python and MySQLdb to download web pages and store them into database. The problem I have is that I can't save complicated strings in the database because they are not properly escaped.
Python中是否有一个可用于转义的函数MySQL的字符串?我尝试使用'''
(三重简单的引号)和,但它没有起作用知道PHP有
mysql_escape_string()
,在Python中类似?
Is there a function in Python that I can use to escape a string for MySQL? I tried with '''
(triple simple quotes) and """
, but it didn't work. I know that PHP has mysql_escape_string()
, is something similar in Python?
谢谢。
推荐答案
conn.escape_string()
请参阅MySQL C API函数映射: http:// mysql-python.sourceforge.net/MySQLdb.html
See MySQL C API function mapping: http://mysql-python.sourceforge.net/MySQLdb.html
这篇关于MySQL转义字符串Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!