python 获取表当前最大id值

#!/usr/bin/python
# -*- coding:utf-8 -*-
#__author__='Kakarotto'
import MySQLdb

conn = MySQLdb.connect(
        host='localhost',
        port=3306,
        user='root',
        passwd='1qazxcde3@wsx',
        db='phonedata',
    )
    cur = conn.cursor()
    sqlii="select max(id) from phoneto"
    cur.execute(sqlii)
    conn.commit()
    maxnumber=cur.fetchall()
    for row in maxnumber:
        countori=row[0]
    count= countori+1 #get primarary key new value
    print count

你可能感兴趣的:(python,python)