import MySQLdb
name="XYZ"
number=(256, 34576312114897154715004917944343995880721156274004613128261928143013598386679L)
db=MySQLdb.Connect("localhost","root","12345","phone")
cursor=db.cursor()
sql= ("""INSERT INTO phonebook(number, Mobile) VALUES(%s,%s)""" , name,number)
cursor.execute(sql)
db.commit()
db.close()
"处理格式参数失败; %S" % 呃) mysql.connector.errors.ProgrammingError:处理格式参数失败; Python' tuple'无法转换为MySQL类型
答案 0 :(得分:2)
您的sql
变量是元组
sql= ("""INSERT INTO phonebook(number, Mobile) VALUES(%s,%s)""" , name,number)
因此,当它尝试执行时,cursor.execute(sql)
(其中sql
为元组)会给出错误 Python' tuple'无法转换为MySQL类型
请使用字符串。
sql = """INSERT INTO phonebook(number, Mobile) VALUES(%s,%s)""" % (name,number)