January 2019
Beginner
318 pages
8h 23m
English
Now, if we want to make some changes in the records, we can use an SQL update statement. We are going to see an example of an update statement. For that, create a update_data.py script and write following content in it:
import MySQLdb as mdbcon_obj = mdb.connect('localhost', 'test_user', 'test123', 'test')cur_obj = con_obj.cursor()cur_obj.execute("UPDATE books SET Name = 'Fantastic Beasts' WHERE Id = 1") try: con_obj.commit()except: con_obj.rollback()
Run the script as follows:
student@ubuntu:~/work/mysql_testing$ python3 update_data.py
Now, to check if your record is updated or not, run retrieve_data.py as follows:
student@ubuntu:~/work/mysql_testing$ python3 retrieve_data.pyOutput:(1, 'Fantastic Beasts')(2, 'Lord of the ...
Read now
Unlock full access