[python] view plaincopy
1. #!/usr/bin/python
2. # import MySQL module
3. import
4. # get user input
5. "Please enter a name: "
6. # connect
7. "localhost""nobody""nobody""qestar""/tmp/mysql.sock"
8. # create a cursor
9.
10. # execute SQL statement
11. "INSERT INTO test (nama) VALUES (%s)"
12. # get ID of last inserted record
13. print"ID of last record is "#最后插入行的主键ID
14. print"ID of inserted record is "#最新插入行的主键ID,conn.insert_id()一定要在conn.commit()之前,否则会返回0
15.
cursor.lastrowid跟conn.insert_id()的结果一般情况下是一样的,最后一条记录肯定就是刚刚插入的记录。但如果是并发插入就不一样了,多线程的时候
¥29.8
¥9.9
¥59.8