python使用MySQLdb插入二進制數據時遇到的錯誤

MySQL Error 1064: 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 'b'\xff\。。。。。。

以上提醒的其實是語法錯誤,平時我用的插入數據的格式是:

 cursor.execute("insert into initlogin(userId,deviceId,pictureFeature,userPass) value('%s','%s','%s','%s')" % ('1031','110','1250146201456','000000'))

但是如果有個字段是blob格式時,使用上述格式是會出現開頭我說的錯誤的,

當有字段是blob,二進制數據插入時,使用以下格式的語句就不會有錯誤了:

cursor.execute('insert into persons_to_updated(ZJ,operationType,facePicture,operationTime) value(%s,%s,%s,%s)',(['1040','new_ad',MySQLdb.Binary(img),dt]))

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章