sql处理
def mysqls_more(sql): # 连接数据库 hostvalue = 'localhost' uservalue = 'root' passwordvalue = 'root' dbvalue = 'book' portvalue = 3306 connection = pymysql.connect(host=hostvalue, user=uservalue, password=passwordvalue, db=dbvalue, port=portvalue,charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) # 通过cursor创建游标 cursor = connection.cursor() # 创建sql 语句,并执行 sqlvalue = sql # "select * from user" rows = cursor.execute(sqlvalue) print(rows) if rows <= 1: result = cursor.fetchone() # 查询数据库单条数据 print(result) else: results = cursor.fetchall() #查询数据库多条数据 print(results) # 提交sql connection.commit() return
心之所向无人可挡