MySQL Forums
Forum List  »  Connector/Python

mysql.connector for binary file save to blob field
Posted by: Min Sun
Date: April 28, 2015 07:14PM

Hi, everyone.

It is my first time to ask for help here.

I use Python 3.4 to try save some imaging file to the longblob field of mysql table. The codes are:

====
import mysql.connector

filename = 'd:/12.jpeg'
print(filename)

f = open(filename, 'rb')
photo = f.read()
f.close()

mydb = mysql.connector.connect(host = '192.168.1.15', database = 'simon', user = 'simon', password = '1234')
mycur = mydb.cursor()

mycur.execute("insert into brand (imaging) values ('%s')", ([photo]))

mydb.commit()

mycur.close()
mydb.close()

======

When I run the code, it is always responsed some error message:

====
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '???' at line 1
====

I really need help for this matter.

Thank you in advance.

Simon

Options: ReplyQuote


Subject
Written By
Posted
mysql.connector for binary file save to blob field
April 28, 2015 07:14PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.