import os
import mysql_operate.mysql_connect as mysql
import re
def insert(user_email, nickname):
cnx = mysql.connect()
cur = cnx.cursor()
# sql = "INSERT INTO users VALUES (%d, %d)"
try:
# print("正在尝试......")
cur.execute("INSERT INTO users VALUES(%r ,%r)" % (user_email, nickname))
print("插入成功!")
mysql.disnect(cnx)
return 1
except Exception as ER_DUP_ENTRY:
#except Exception as e:
# print("发生错误,错误信息为:", e)
# mmm = '1062 (23000): Duplicate entry \'[\S]*\' for key \'PRIMARY\''
# print(str(e))
# print(mmm)
#
#
#
# if(re.search(mmm , str(e))):
# print("该用户已注册!")
print("成功了")
mysql.disnect(cnx)
return 0
mysql.disnect(cnx)
if __name__ == "__main__":
email = "test_email1@qq.com"
nickname = "hahahaha"
insert(email, nickname)