PyMysql-Python:如何检查用户提供的输入是否存在于我的数据库中
PyMysql-Python:How to check if an input a user gives exists in my database
我有一个 table 这样的:
Movies:
Title Rank
a 5
b 6
b 6.5
c 7
假设这就是我的 table.I 想要查找用户从他的键盘输入的输入(电影的标题)是否存在于我的数据库中,以及他选择的电影是否只存在于 table.
如果你想检查 sql query
>>> user_input = input('Enter movie title: ')
>>> sql_query = 'select title from movie where title = {}'.format(user_input)
>>> cursor.execute(sql_query)
>>> result = cursor.fetchone()
>>> row = result[0]
或者如果您的查询结果在数据框中:
>>> user_input in df['Title'].tolist()
我有一个 table 这样的:
Movies:
Title Rank
a 5
b 6
b 6.5
c 7
假设这就是我的 table.I 想要查找用户从他的键盘输入的输入(电影的标题)是否存在于我的数据库中,以及他选择的电影是否只存在于 table.
如果你想检查 sql query
>>> user_input = input('Enter movie title: ')
>>> sql_query = 'select title from movie where title = {}'.format(user_input)
>>> cursor.execute(sql_query)
>>> result = cursor.fetchone()
>>> row = result[0]
或者如果您的查询结果在数据框中:
>>> user_input in df['Title'].tolist()