我有一个简单的注册表单,可以在“学生”表中创建一条新记录:
cur = con.cursor()
query = "INSERT INTO students (Name, Address, Major, Phone, Email, Password) values (%s, %s, %s, %s, %s, %s)"
args = [name, address, major,phone, email, password]
cur.execute(query, args)
con.commit()
列Id自动递增,因此为了获得最后一个Id,我选择Max
query = "SELECT MAX(Id) FROM students;"
cur.execute(query)
id = cur.fetchone()[0]
它适用于我的小作业项目,但如何在一个重载项目中完成,在select语句之前有可能创建一些东西?