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"%(chat_id)
- cursor.execute(sql)
- numrow=cursor.fetchall()
- db.commit()
- if numrow :
- print ("Record gia' presente")
- else :
- try :
- sql2= " INSERT INTO user VALUES (%d,'%s', %d)" %(chat_id,username,7000)
- cursor.execute(sql2)
- db.commit()
- print ("new user add id %d username : %s" %(chat_id,username))
- except :
- db.rollback()
- db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement