Quantcast
Channel: MySQL Forums - Connector/Python
Viewing all articles
Browse latest Browse all 384

mysql.connector for binary file save to blob field (2 replies)

$
0
0
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

Viewing all articles
Browse latest Browse all 384

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>