用于 MySQL 的转义字符串 Python

Escape string Python for MySQL(用于 MySQL 的转义字符串 Python)
本文介绍了用于 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)