0

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.

0

1 Answer 1

1

I dont think you are calling the access_db() function anywhere

Sign up to request clarification or add additional context in comments.

1 Comment

My bad. Thanx for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.