Advertisement
Guest User

Untitled

a guest
Mar 9th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import pymysql
  2. db = pymysql.connect(host='localhost',
  3.                              user='root',
  4.                              password='123456',
  5.                              db='testdb')
  6.  
  7.  
  8. cursor=db.cursor()
  9.  
  10. def add_new_user(chat_id,username):
  11.     sql = "SELECT chat_id FROM user WHERE chat_id=%d"%(chat_id)
  12.     cursor.execute(sql)
  13.     numrow=cursor.fetchall()
  14.     db.commit()
  15.     if numrow :
  16.         print ("Record gia' presente")
  17.     else :
  18.         try :
  19.             sql2= " INSERT INTO user VALUES (%d,'%s', %d)" %(chat_id,username,7000)
  20.             cursor.execute(sql2)
  21.             db.commit()
  22.             print ("new user add id %d username : %s" %(chat_id,username))
  23.         except :
  24.             db.rollback()
  25.  
  26.  
  27. db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement