Products
GG网络技术分享 2025-11-14 07:01 1
根据所给的内容,
bash
pip install pymysql

python import pymysql
conn = pymysql.connect cursor = conn.cursor
cursor.execute
sql = """ CREATE TABLE IF NOT EXISTS person ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR NOT NULL, age INT )""" cursor.execute
cursor.close conn.close
python class Database: def init: self.conn = pymysql.connect self.cursor = self.conn.cursor
def execute:
if params:
self.cursor.execute
else:
self.cursor.execute
return self.cursor
def fetchall:
return self.cursor.fetchall
def commit:
self.conn.commit
def close:
self.cursor.close
self.conn.close
python db = Database
db.execute VALUES ", ) db.commit
results = db.execute for row in results: print
db.execute) db.commit
db.close
data =
请根据实际情况替换yourpassword和其他连接信息。
Demand feedback