Пример #1
0
def fetchuserlist():
    conn = getconnection()
    try:
        c = conn.cursor()
        c.execute("select * from usertableofheros")
        value = c.fetchall()
        return value
    except BaseException:
        conn.rollback()
        mylogger.debug(BaseException + "Error happenedd")
    finally:
        conn.close()
Пример #2
0
def updateWeapon(weaponid):
    conn = getconnection()
    try:
        c = conn.cursor()
        c.execute('update weapontable set val=val+20 where weaponid=%s',
                  (weaponid))
        conn.commit()
        return resultStatus("update success")
    except:
        conn.rollback()
        mylogger.debug("update error")
        return resultStatus("update error")
    finally:
        conn.close()
Пример #3
0
def adduser(user):
    username = user.username
    password = user.password
    if (len(username) == 0 or len(password) == 0):
        return resultStatus("length of string is zero")
    if (username is None or password is None):
        return resultStatus("None data")
    conn = getconnection()
    try:
        c = conn.cursor()
        c.execute(
            'insert into usertableofheros (username,password) values(%s,%s)',
            (username, password))
        conn.commit()
        return resultStatus("insert success")
    except:
        mylogger.debug(BaseException)
        conn.rollback()
        return resultStatus("error happened")
    finally:
        conn.close()
Пример #4
0
def getconnection():
    # try:
    # with pymysql.Connect(host="127.0.0.1",user='******', password='******', db="herogame",charset="utf8mb4") as conn:
    #         print(type(conn))
    #         return conn
    # except:
    #     return
    try:
        conn = pymysql.Connect(host="127.0.0.1",
                               user='******',
                               password='******',
                               db="herogame",
                               charset="utf8mb4")
        if (not conn):
            mylogger.debug("connect failed")
            print("connect failed,quit()")
            quit()
        else:
            return conn
    except:
        print("connect failed,quit()")
        quit()
Пример #5
0
#!python
# -*- coding: UTF-8 -*-
#%%

import cgi, cgitb 
import json
import dbUtil
from pojo import User
# 创建 FieldStorage 的实例化
import mylogger
# 获取数据
cgitb.enable(display=0, logdir="f:\logdir")
form = cgi.FieldStorage() 
username = form.getvalue("username")
password = form.getvalue("password")
mylogger.debug(username)
mylogger.debug(password)
try:
    result=dbUtil.adduser(User(username,password))
    jsonobject=json.dumps(result)
    print("Content-type:json")
    print()
    print(jsonobject)
except BaseException:
    mylogger.debug("service throw excepttion"+result)
finally:
    pass