Advertisement
Guest User

Untitled

a guest
Mar 9th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 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"
  12.     cursor.execute(sql,chat_id)
  13.     numrow=cursor.fetchall()
  14.     db.commit()
  15.     if numrow :
  16.         print ("Record gia' presente")
  17.     else :
  18.         #print (1)
  19.         try :
  20.             sql2= "INSERT INTO user VALUES (%d,%s, %d)"
  21.             #print (2)
  22.             cursor.execute(sql2,(chat_id,username,7000))
  23.             #print (3)
  24.             db.commit()
  25.             #print (4)
  26.             print ("new user add id %d username : %s" %(chat_id,username))
  27.             #print (5)
  28.         except :
  29.             db.rollback()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement