python怎么找到前台传进的主键
展开全部
#!/usr/bin/python
# import MySQL module
import MySQLdb
# get user input
name = raw_input("Please enter a name: ")
# connect
db = MySQLdb.connect(host="localhost", user="nobody", passwd="nobody", db="qestar", unix_socket="/tmp/mysql.sock")
# create a cursor
cursor = db.cursor()
# execute SQL statement
cursor.execute("INSERT INTO test (nama) VALUES (%s)", name)
# get ID of last inserted record
print "ID of inserted record is ", int(cursor.lastrowid)
# import MySQL module
import MySQLdb
# get user input
name = raw_input("Please enter a name: ")
# connect
db = MySQLdb.connect(host="localhost", user="nobody", passwd="nobody", db="qestar", unix_socket="/tmp/mysql.sock")
# create a cursor
cursor = db.cursor()
# execute SQL statement
cursor.execute("INSERT INTO test (nama) VALUES (%s)", name)
# get ID of last inserted record
print "ID of inserted record is ", int(cursor.lastrowid)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询