如何解决在python中从MySql数据库获取数据时出错
我正在尝试使用Python中的WHERE子句从MysqL数据库中获取密码,并将密码存储在变量“ DbPassword”中,但是当我打印“ DbPassword”时,它将打印“ None” 谁能解释为什么会这样,我该如何解决? 谢谢I have attached a ScreenShot of my IDE where the entire function and Output can be seen
def searchdb(self):
User = (self.Username.get())
pas = (self.Password.get())
myconn = MysqL.connector.connect(host = "localhost",user = "root",passwd = "qwerty321",database = "admin")
if len(User) == 0 and len(pas) == 0 :
tkinter.messageBox.showinfo("Pharmacy Management System","Please fill in the Login Details")
elif len(User) == 0 and len(pas) != 0 :
tkinter.messageBox.showinfo("Pharmacy Management System","Please Enter a Username")
elif len(User) != 0 and len(pas) == 0:
tkinter.messageBox.showinfo("Pharmacy Management System","Please enter a Password")
else:
try:
#seacrch data
#print("%s\n%s"%(User,pas) )
sql = "SELECT password FROM users WHERE user_name = '%s'"
cur = myconn.cursor()
cur.execute(sql,(User))
DbPassword = cur.fetchone()
print("%s"%(DbPassword))
if (pas == str(DbPassword)) :
self.btnRegistration.config(state=norMAL)
self.btnHospital.config(state=norMAL)
else:
tkinter.messageBox.askokcancel("Pharmacy Management System","You have entered an invalid login details")
self.btnRegistration.config(state=disABLED)
self.btnHospital.config(state=disABLED)
self.Username.set("")
self.Password.set("")
self.txtUsername.focus()
except Error as e:
# tkinter.messageBox.showinfo("Pharmacy Management System","NO RECORD FOUND !")
myconn.rollback()
Window1.Reset(self)
myconn.close()
解决方法
最后获得答案进行了一些更改
修改: $products = [];
for ($i = 0; $i < count($data['products']); $i++) {
$recipes[$data['products'][$i]['id']] = $data['products'][$i];
unset($products[$data['products'][$i]['id']]['id']);
}
$budget->products()->sync($products);
$budget->products = $data['products'];
到: sql = "SELECT password FROM users WHERE user_name = '%s'" cur.execute(sql,(User))
并按预期工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。