SystemError:“\u mysql\u connector.mysql”objects>的<method“fetch\u row”返回了一个结果,错误为%s

2024-06-27 02:30:54 发布

您现在位置:Python中文网/ 问答频道 /正文

导入mysql.connector 从mysql.connector导入错误

def write\文件(数据,文件名):

with open(filename, 'wb') as file:
    file.write(data)

def readBLOB(环境标识、照片、生物数据): print(“从python\u employee表读取BLOB数据”)

try:
    connection = mysql.connector.connect(host='localhost',
                                         database='image',
                                         user='root',
                                         password='root')

    cursor = connection.cursor()
    sql_fetch_blob_query = """SELECT photo from python_employee where id = %s"""

    cursor.execute(sql_fetch_blob_query,(emp_id,))
    record = cursor.fetchall()
    for row in record:
        print("Id = ", row[0],)
        print("Name = ", row[1])
        image = row[2]
        file = row[3]
        print("Storing employee image and bio-data on disk \n")
        write_file(image, photo)
        write_file(file, bioData)

except mysql.connector.Error as error:
    print("Failed to read BLOB data from MySQL table {}".format(error))

finally:
    if (connection.is_connected()):
        cursor.close()
        connection.close()
        print("MySQL connection is closed")

readBLOB(1,“E:\images\krishna.jpg”, “E:/text/eric.txt”)

readBLOB(2,“E:\images\shiva.jpg”, “E:/text/scott.txt”)


Tags: 数据imagedataconnectordefasmysqlemployee