views:

162

answers:

2

Hello,

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 into database because they are not escaped properly.

Is there a function in Python I can use to escape a string for MySQL? I tried with ''' (tiple simple quotes) and """, but it didn't work. I know that PHP has mysql_escape_string(), is something similar in Python?

Thanks,

A: 
conn.escape_string()

See MySQL C API function mapping: http://mysql-python.sourceforge.net/MySQLdb.html

The MYYN
Thanks, it worked!
Laurențiu Dascălu
+2  A: 

Python's DB-API solves this in a much cleaner way - instead of commingling the statement and the data, it uses parametrized queries. See the accepted answer to http://stackoverflow.com/questions/775296/python-mysql-with-variables for one example of how to use these with mysqldb

TML
Thanks for your answer, too.
Laurențiu Dascălu