Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql
- db = pymysql.connect(host='localhost',
- user='root',
- password='123456',
- db='testdb')
- cursor=db.cursor()
- def add_new_user(chat_id,username):
- sql = "SELECT chat_id FROM user WHERE chat_id=%d"
- cursor.execute(sql,chat_id)
- numrow=cursor.fetchall()
- db.commit()
- if numrow :
- print ("Record gia' presente")
- else :
- #print (1)
- try :
- sql2= "INSERT INTO user VALUES (%d,%s, %d)"
- #print (2)
- cursor.execute(sql2,(chat_id,username,7000))
- #print (3)
- db.commit()
- #print (4)
- print ("new user add id %d username : %s" %(chat_id,username))
- #print (5)
- except :
- db.rollback()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement