Escape string Python for MySQL(用于 MySQL 的转义字符串 Python)
问题描述
我使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于 MySQL 的转义字符串 Python
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
