Devdit
 

mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement คือ วิธีแก้ไข

1.1K

รันโค้ดเพิ่มข้อมูลลง MySQL แบบหลายๆ ข้อมูลด้วยคำสั่ง executemany ของภาษา Python แต่ไม่สำเร็จขึ้นข้อความว่า mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement แบบนี้ต้องแก้ไขอย่างไร

sql = ' INSERT INTO test (name) VALUES (%s) '
data = [("Python"),("MySQL"),("SQL")]
cur = cnx.cursor()
cur.executemany( sql, data )
cnx.commit()

 

วิธีแก้ไข

กรณีมี Field เดียวแนะนำให้ใส่เครื่องหมายจุลภาค หรือ ลูกน้ำ ( , ) หลังข้อมูลในตัวแปร data ทั้งหมด คือ ("Python", ),("MySQL", ),("SQL", )

sql = ' INSERT INTO test (name) VALUES (%s) '
data = [("Python",),("MySQL",),("SQL",)]
cur = cnx.cursor()
cur.executemany( sql, data )
cnx.commit()
แก้ไข 2 ปีที่แล้ว
ชอบ
ลิ้งก์
แชร์
Devdit มีช่อง YouTube แล้ว
เราสร้างวิดีโอเกี่ยวกับเทคโนโลยี ทำตามง่ายๆ