if cursor.execute(sql,(id,user,age)):
上面这行代码,sql中的3个占位符(VALUES(%s,%s,%s))是如何与后面的元组(id,user,name)关联起来的?占位符%s后面不是要加%再跟要代替的值吗?
import pymysql
db = pymysql.connect(host='localhost',user='root',passwd='***',port=3306,db='spiders')
cursor = db.cursor()
id = '20120001'
user = 'Bob'
age = 20
sql = 'INSERT INTO students(id,user,age) VALUES(%s,%s,%s)'
try:
if cursor.execute(sql,(id,user,age)):
print('Successful')
db.commit()
except:
print('Failed')
db.rollback()
db.close()