Home Page class 12 @ Python

Python Interface with MySQL

student mysql connectivity programs
Student Data Base With MySQL using mysql.connector

Connecting python with mysql database
to create a database
to create a table within a database
insert the data into table
to insert data into a table by taking input for the details
insert multiple records in the table
to display only one record from a table
to display all records from a table
to display selected columns from the table
searching a record by roll no
searching a record by name
delete by name
update all records
update all records

Student Details connectivity with MySQL using pymysql
Bank Details connectivity with MySQL using pymysql

class 12 Interface python with SQL 5

Program:14

#14
#update all records
#to display all records from a table
#select command

import mysql.connector
from mysql.connector import Error
con=None
try:
    con = mysql.connector.connect(host='localhost',user='root',
password='ct',database='student1')
    if(con.is_connected()==True):
        print("connected")
    db=con.cursor()
    sql="update stud set per=(total*100)/500"
    db.execute(sql)
    sql="select * from stud"
    db.execute(sql)
    res = db.fetchall()
    for x in res:
        print(x)
    con.commit();
except Error as e:
        print(e)
finally:
        if con is not None and con.is_connected():
            con.close()
            print("Connection closed")