From fae039df5dd9547ae8a9d49252bc235c29b1401e Mon Sep 17 00:00:00 2001 From: wolin_ck666_999 Date: Sat, 19 Sep 2026 15:02:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=E3=80=8C/=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- testLine.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 testLine.py diff --git a/testLine.py b/testLine.py new file mode 100644 index 0000000..3efd19e --- /dev/null +++ b/testLine.py @@ -0,0 +1,41 @@ +import pymysql + +# 创建数据库连接 +db = pymysql.connect( + host="localhost", + user="root", + passwd="123456", + database="ai0824" +) +print('数据库连接成功!') + +# 1.创建游标对象 +cursor =db.cursor() +# 2.执行sql查询语句 +# cursor.execute("select * from ai0824_student") +# results = cursor.fetchall() +# for row in results: +# print(row) +# print(f'获取的所有结果为:{results}') +# 3.执行sql插入语句 +# sql = "insert into test0905 values(%s,%s)" +# l = [(1,'张三'),(2,'李四'),(4,'赵六')] +# cursor.execute(sql, l) +# cursor.executemany(sql, l) +# db.commit() +# 4.执行update更新语句 +# sql = "update test0905 set name = %s where id = %s" +# values=('李四',2) +# cursor.execute(sql,('李四',2)) +# db.commit() +# print(cursor.rowcount,'条记录更新成功') +# 5.执行sql删除语句 +# sql = "delete from test0905 where id = %s" +# values= 2 +# cursor.execute(sql,2) +# db.commit() +# print(cursor.rowcount,'条记录删除成功') + +db.close() +cursor.close() +print("数据库连接已关闭!") \ No newline at end of file