storing binary files to mySQL ???
Fredrik Lundh
fredrik at pythonware.com
Mon Dec 16 14:58:08 EST 2002
"steindl fritz" <python at floSoft.org> wrote:
> i try to store pictures in a blob field of mySQL
>
>
> file = open("c:\\picture.jpg", 'rb')
> picture = file.read()
>
> SQL ='INSERT INTO tbl_BLOB (attrName, attrValue) VALUES
> ("nameOfPicture", ' + picture + ')'
>
> conn = CompatMysqldb.Connection("host", "username", "password", "db")
> curs = conn.cursor()
> curs.execute(SQL)
what MySQL module are you using?
("python CompatMysql" (without the quotes) is a googlewhack
on groups.google.com, and returns no hits at all on other parts
of google.)
anyway, in case this is Andy Dustman's version, and nothing else
helps, you can always import _mysql and use the escape_string
function:
import _mysql
file = open("c:\\picture.jpg", 'rb')
picture = _mysql.escape_string(file.read())
I'm pretty sure there's a better way, but I just un-
installed MySQL on this box, so I'll have to leave it
to someone else to tell you what it is.
</F>
More information about the Python-list
mailing list