sqlite3 是一个python中内置数据库,执行时会在本地文件夹中创建一个数据库
import sqlite3 # 连接到数据库,如果数据库不存在,则会被创建 conn = sqlite3.connect('example.db') # 创建一个cursor对象 cursor = conn.cursor() # 创建表格的SQL命令 create_table_query = """CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL, password TEXT NOT NULL, locking TEXT NOT NULL );""" # 执行SQL命令 # cursor.execute(create_table_query) # 插入数据 # cursor.execute('''INSERT INTO users VALUES (1, '1231111','123456','0')''') cursor.execute('''UPDATE users SET locking ='0' WHERE ID = 1''') rows = cursor.fetchall() # 提交事务 conn.commit()
标签:users,python,TEXT,cursor,sqlite3,SQLite3,NULL,conn From: https://www.cnblogs.com/GDquicksand/p/18235465