使用sqlite3内置模块连接SQLite数据库(示例):
import sqlite3
# 建立与数据库的连接
conn = sqlite3.connect('mydatabase.db')
cursor = conn.cursor()
# 执行查询语句
sql = "SELECT * FROM mytable"
cursor.execute(sql)
result = cursor.fetchall()
print(result)
# 关闭连接
cursor.close()
conn.close()
powered by kaifamiao