我尝试使用两种方法将数据插入mysql数据库,但总共出错:在第一种方法中:
sql = ('''Insert into lgemployees (EmpID,Name,Gender,DOB,Address,PhoneNumber,Email)
VALUES (%d,$s,$s,$s,$s,$d,$s)''', (eid, name, gen, dob, add, mob, email))
mycursor.execute(sql)
mycursor.commit()此方法中的错误:
'tuple' object has no attribute 'encode'第二种方法:
sql = "Insert into lgemployees (EmpID,Name,Gender,DOB,Address,PhoneNumber,Email) VALUES(?,?,?,?,?,?,?,)"
val = (eid, name, gen, dob, add, mob, email)
mycursor.execute(sql, val)
mycursor.commit()此方法中的错误:
"Not all parameters were used in the SQL statement")
mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement我已经解决了很多从我的结束,但没有运气。任何人都可以帮忙吗,因为我哪里错了,或者还有什么是从python向mysql插入数据的好选择。
发布于 2019-07-19 11:32:43
我不知道您的错误在哪里,但是我已经用这段代码进行了测试,它可以工作。
insert_tuple = (eid, name, gen, dob, add, mob, email)
sql = """INSERT INTO lgemployees (`EmpID `,
`Name`,`Gender`, `DOB`, `Address`, `PhoneNumber`, `Email`)
VALUES (%s,%s,%s,%s,%s,%s,%s)"""
mycursor = mySQLconnection.cursor()
mycursor.execute(sql, insert_tuple)
mySQLconnection.commit()
mycursor.close()您的代码抛出此值,因为其中一个参数是空的,或者是它无法读取的格式。
"Not all parameters were used in the SQL statement")
mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statementhttps://stackoverflow.com/questions/57111211
复制相似问题