import mysql.connector
mydb = mysql.connector.connect(host= 'localhost', user='root', passwd="barbie", db='data')
mycursor = mydb.cursor() #execute, fetch data act as a pointer
print("Connected to database")
query = ("select name , matric from users where username = %s")
username = 'shawn'
mycursor.execute(query, (username))
print ("Fetching single row")
record = mycursor.fetchone
print (record)
错误
为什么会出现这种错误?我只想显示行
数据库中的表
错误是如何将参数传递给
execute
execute
接受一个iterable(list/tuple),但您只传递一个值。以下两行是等效的要使元组只包含1个元素,需要添加逗号(,)
相关问题 更多 >
编程相关推荐