简体   繁体   中英

insert into python mysql not updating in DB

I tried inserting the values into the DB through python. However i do not get any error but i do not see it updating in DB. Please advice.

#!/usr/bin/python

import MySQLdb

val = MySQLdb.connect(host='localhost', user='root', passwd='root123', 
db='expenses')

def access_db(val):
    access = val.cursor()
    sql = """Insert into monthly values (2,'Food',1000)"""
    access.execute(sql)
 val.commit()
 val.close() 

Output from DB after the script execution:

MariaDB[expenses]> select * from monthly;
SL_no     Type    Amount
  1       Fuel     500

I do not find the second entry in Db.

我不认为您在任何地方都调用access_db()函数

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM