how to insert image into database sqlite3 and Python

PHOTO EMBED

Wed Aug 14 2024 13:57:42 GMT+0000 (Coordinated Universal Time)

Saved by @freepythoncode ##python #coding #python #programming #database #sqllite3 #image

import sqlite3

db = sqlite3.connect('mydb.db')
cur = db.cursor()

# create users table
cur.execute('CREATE TABLE IF NOT EXISTS users (name str, image blob)')

# insert new user in users table
cur.execute(
    'INSERT INTO users (name, image) VALUES (?, ?)', 
    ('USER-123', open('smile.png', 'rb').read())
)

db.commit()
content_copyCOPY