【发布时间】:2021-05-01 10:27:54
【问题描述】:
我将 mysql.connector 模块用于我的脚本。
这里是我的脚本,我尝试检查: 我的数据库结构: 名称、类型、prem、块
class database():
def __init__(self):
self.Database = mysql.connect(
host='localhost',
user='root',
password='',
auth_plugin='mysql_native_password'
)
self.cursor = self.Database.cursor()
def GetProfileInformations(self, name):
args = name.split(' ')
found = self.cursor.execute('SELECT * FROM list.raids WHERE name=' + args[0])
sql = self.cursor.execute('SELECT * FROM list.raids')
rc = self.cursor.fetchall(sql)
f = self.cursor.fetchall(found)
# Check is imput equal to name
for _ in f:
if not found:
return
for row in rc:
try:
if row[0] == args[0]:
if row[3] == 1:
if row[2] == 1:
print(f"Name {row[0]} found with 1")
else:
print(f"Name: {row[0]} found with 0")
else:
print(f"Name: {row[0]} found but is blocked")
except:
print("any error")
self.cursor.close()
现在我的问题是为什么不使用 if exists 函数?
if not found:
return
祝你有美好的一天,感谢你帮助我
【问题讨论】:
标签: python python-2.7 mysql-python python-3.8