def updateSingleField(field='', value=''): mydb = mysql.connector.connect(host=dbConf.host(), user=dbConf.user(), passwd=dbConf.passwd(), database=dbConf.database()) mycursor = mydb.cursor(dictionary=True, buffered=True) sql = "UPDATE `tbl_broker` SET `VALUE`='" + value + "' WHERE FIELD = '" + field + "';" mycursor.execute(sql) mydb.commit() mydb.close() return mycursor.rowcount
def auth(user, psw): mydb = mysql.connector.connect(host=dbConf.host(), user=dbConf.user(), passwd=dbConf.passwd(), database=dbConf.database()) mycursor = mydb.cursor(dictionary=True, buffered=True) sql = "SELECT * FROM tbl_user WHERE tbl_user.user = '******' AND password=PASSWORD('" + psw + "')" #print sql mycursor.execute(sql) myresult = mycursor.fetchall() mydb.commit() mydb.close() return myresult
def updateField(parameter): mydb = mysql.connector.connect(host=dbConf.host(), user=dbConf.user(), passwd=dbConf.passwd(), database=dbConf.database()) mycursor = mydb.cursor(dictionary=True, buffered=True) rows = [] for key, value in parameter.items(): sql = "UPDATE `tbl_broker` SET `VALUE`='" + value + "' WHERE FIELD = '" + key + "';" mycursor.execute(sql) mydb.commit() mydb.close() return mycursor.rowcount
def getSingleValue(field=''): mydb = mysql.connector.connect(host=dbConf.host(), user=dbConf.user(), passwd=dbConf.passwd(), database=dbConf.database()) mycursor = mydb.cursor(dictionary=True, buffered=True) sql = "SELECT * FROM tbl_broker WHERE tbl_broker.FIELD = '" + field + "'" mycursor.execute(sql) myresult = mycursor.fetchall() arrResult = {} for v in myresult: arrResult[v['FIELD']] = v['VALUE'] return arrResult mydb.commit() mydb.close()
mydb.update_student(student) self.update_table() def delete_student(self): id = self.widget_entries[10].get() if len(id) == 0: self.popup_msg("Specify Student ID") return mydb.delete_student(id) self.update_table() def popup_msg(self, msg): popup = Tk() popup.geometry("235x85") popup.resizable(width=False, height=False) popup.wm_title("Enter All Values") err_msg = Text(popup, font=("Verdana", 16)) err_msg.insert(INSERT, msg) err_msg.pack() ok_button = ttk.Button(popup, text="Close", command=popup.destroy) ok_button.place(relx=.5, rely=.8, anchor="center") popup.mainloop() root = Tk() root.geometry("1400x600") root.title('Student Database') mydb = database()