Python MySql Insert not working

前端 未结 4 1111
离开以前
离开以前 2020-12-01 10:14

I am using python MySQL API to connect to Mysql database from python program. I am facing a problem from few days. I am unable to insert records into the database and dont k

相关标签:
4条回答
  • 2020-12-01 10:41

    if you are using InnoDB engine in MySQL you should add

    db.commit() 
    

    else change your MySQL engine into MyISAM no need to change anything in code.

    0 讨论(0)
  • 2020-12-01 10:42

    You may set python to autocommit changes in your database like this:

    db = MySQLdb.connect("localhost","root","padmaramulu","pdfsearch, autocommit=True")```
    
    0 讨论(0)
  • 2020-12-01 10:44

    I think your code should be fixed

    cursor.execute( 'insert into documents(docid,docname) values(%d, %s)', (number,temp) )
    

    and then You should add db.commit() before you close database connection.

    0 讨论(0)
  • 2020-12-01 10:48

    Before closing the connection, you should add db.commit().

    0 讨论(0)
提交回复
热议问题