亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: python插入記錄后取得主鍵id的方法 [打印本頁]

作者: 都是蟲子惹的禍    時間: 2009-03-05 18:21
標(biāo)題: python插入記錄后取得主鍵id的方法
#!/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)
作者: luffy.deng    時間: 2009-03-05 18:36
??
作者: xiaoyu9805119    時間: 2009-03-06 08:53
原帖由 都是蟲子惹的禍 于 2009-3-5 18:21 發(fā)表
#!/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", passw ...

不知道是不是調(diào)用mysql自帶的last_insert_id()函數(shù)
作者: 都是蟲子惹的禍    時間: 2009-03-06 08:56
# get ID of last inserted record
print "ID of inserted record is ", int(cursor.lastrowid)
作者: luffy.deng    時間: 2009-03-06 08:59
這個到底是想說明什么問題?lastrowid和主鍵id有什么關(guān)系?主鍵id是什么意思?

另外這個是不是msysql特有的,還是適用于所有數(shù)據(jù)庫?

[ 本帖最后由 luffy.deng 于 2009-3-6 09:00 編輯 ]
作者: xiaoyu9805119    時間: 2009-03-06 09:04
原帖由 luffy.deng 于 2009-3-6 08:59 發(fā)表
這個到底是想說明什么問題?lastrowid和主鍵id有什么關(guān)系?主鍵id是什么意思?

另外這個是不是msysql特有的,還是適用于所有數(shù)據(jù)庫?

可能樓主是想帖出怎么獲取last insert id把
應(yīng)該是調(diào)用mysql自帶函數(shù),其他數(shù)據(jù)庫可能函數(shù)不一樣把。
作者: luffy.deng    時間: 2009-03-06 09:06
主鍵就是主鍵,行id就是行id ,主鍵id是什么意思?
作者: xiaoyu9805119    時間: 2009-03-06 15:33
原帖由 luffy.deng 于 2009-3-6 09:06 發(fā)表
主鍵就是主鍵,行id就是行id ,主鍵id是什么意思?

人家帖出來也不容易,呵呵,可能只是想獲取最后的insert id把。




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2