Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python MySQLdb-简单语句错误_Python_Mysql_Insert_Mysql Python - Fatal编程技术网

Python MySQLdb-简单语句错误

Python MySQLdb-简单语句错误,python,mysql,insert,mysql-python,Python,Mysql,Insert,Mysql Python,这句话有错误,我似乎不明白为什么。有什么想法吗?表media_files btw只有两列,ID和数据,每列都是VARCHAR(255) 谢谢 特伦特 使用括号可以解决问题。您正在插入一条数据,但提供了两个字段 db = MySQLdb.connect("XXXXXXXX","root", "XXXXXX", database) cursor = db.cursor() cursor.execute('INSERT INTO media_files (ID, DATA) VALUES ("tes

这句话有错误,我似乎不明白为什么。有什么想法吗?表media_files btw只有两列,ID和数据,每列都是VARCHAR(255)

谢谢 特伦特

使用括号可以解决问题。您正在插入一条数据,但提供了两个字段

db = MySQLdb.connect("XXXXXXXX","root", "XXXXXX", database)
cursor = db.cursor() 
cursor.execute('INSERT INTO media_files (ID, DATA) VALUES ("test", "test")')
cursor.execute("commit")
'INSERT INTO media_files (ID, DATA) VALUES ("test", "test")'