python project with database connectivity

Solutions on MaxInterview for python project with database connectivity by the best coders in the world

showing results for - "python project with database connectivity"
Samuel
28 Feb 2020
1#APPARENTLY IT IS NOT POSSIBLE TO UPLOAD TOO LONG CODES HERE
2# AND MY PROJECT IS OVER 1800 LINES DISTRIBUTED OVER 3 FILES... SO
3# HERE ARE THE BASICS... HOPE YOU CAN BUILD UP YOUR OWN PROJECT USING THIS
4# THIS IS AN EXAMPLE JUST EXPLAINING THE BASICS OF DATABASE MANNAGEMENT IN PYTHON
5# HOPE YOU CAN BUILD UP FROM HERE
6import mysql.connector as MC
7try:
8    Con_o = MC.connect(host="localhost",user="root",passwd="sidspc12345",database="mydb")
9    if Con_o.is_connected():
10        print("Connection established successfully")
11except Exception as E:
12    print("Connection Failed !")
13    print("ERROR : ",e)
14
15Cur = Con_o.cursor()
16Cur.execute("select * from  students where Percentage>= 95")
17
18data = Cur.fetchall()
19
20for row in data:
21    print(row)
22
23Con_o.commit()
24st = "INSERT INTO students(Roll,Name,Sex,Stream,Phone,Address,Maths,Science,SST,English,Hindi) values({},'{}','{}','{}',{},'{}',{},{},{},{},{})".format(11021,'Siddharth','M','S',7002744892,'Second link road Silchar',100,100,100,94,88)
25Cur.execute(st)
26Con_o.commit()
27
28Cur.execute("select * from  students")
29
30data = Cur.fetchall()
31
32for row in data:
33    print(row)
34Con_o.close()
35