about escape string store in mysql

Steve Holden steve at holdenweb.com
Sun Nov 16 19:07:24 CET 2008


MRAB wrote:
> On Nov 16, 7:05 am, ylj... at gmail.com wrote:
>> this string from web by the Regular Expression,
>> −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
>> href="#" onClick="ConvertURL2FG('Flashget://
>> W0ZMQVNIR0VUXWh0dHA6Ly9tb3YuM2dwLmNuL2d1aWxpbi8yMDA4LzExLzExL3l1ZWhvdWppZmVuMDIuM2dwW0ZMQVNIR0VUXQ==&233','',
>> 233)" oncontextmenu="Flashget_SetHref(this)" fg="Flashget://
>> W0ZMQVNIR0VUXWh0dHA6Ly9tb3YuM2dwLmNuL2d1aWxpbi8yMDA4LzExLzExL3l1ZWhvdWppZmVuMDIuM2dwW0ZMQVNIR0VUXQ==&233"
>> −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
>> my code:
>>
>> ******************************************************************************
>> # -*- coding: utf8 -*-
>> #!/usr/bin/python
>>
>> import MySQLdb
>> conn=MySQLdb.connect
>> (host="localhost",user="root",passwd="ylj",db="net", charset="utf8")
>> cur = conn.cursor()
>> s="""href="#" onClick="ConvertURL2FG('Flashget://
>> W0ZMQVNIR0VUXWh0dHA6Ly9tb3YuM2dwLmNuL2d1aWxpbi8yMDA4LzExLzExL3l1ZWhvdWppZmVuMDIuM2dwW0ZMQVNIR0VUXQ==&233','',
>> 233)" oncontextmenu="Flashget_SetHref(this)" fg="Flashget://
>> W0ZMQVNIR0VUXWh0dHA6Ly9tb3YuM2dwLmNuL2d1aWxpbi8yMDA4LzExLzExL3l1ZWhvdWppZmVuMDIuM2dwW0ZMQVNIR0VUXQ==&233""""
>> s=mysqldb.escape_string(s)
>> sql='insert into download(lines) values(%s)'
>> cur.execute(sql, s)
>>
>> ************************************************************
>>
>> when I used the mysqldb.escape_string(),but eric gave me a error,tell
>> me that my sql strings have escape string.
>> how can i put the strings in database.
> 
> The string that you're trying to put into the database ends ...=&233",
> so when you triple-quote it you get ...=&233"""". Python sees this
> as ...=&233""" (triple quotes end the triple-quoted string) followed
> by " and then the end of the line.
> 
> Try escaping the quote after ...=&233, ie ...=&233\"""".

Or. simpler, use tripled single quotes as your string delimiters.

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list