上传文件至「/」
This commit is contained in:
+41
@@ -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("数据库连接已关闭!")
|
||||
Reference in New Issue
Block a user