IP Project
IP Project
Database Connectivity:
To create a connection between the MySQL database and
Python, the connect() method of mysql. connector module is
used. We pass the database details like HostName,
username, and password in the method call, and then the
method returns the connection object.
Database Structure:
Tables:
tdlcommunity:
tdldata:
Project code and output:
Database connectivity:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",
passwd="root",database="todolist")
if mydb.is_connected():
mycursor=mydb.cursor()
print('successfully connected')
Code:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="root",da
tabase="todolist")
if mydb.is_connected():
mycursor=mydb.cursor()
print('successfully connected')
while True:
#adding a new userID and username to create a new user account in database
if(x==1):
un=input("create a username:")
mycursor.execute(sqlinsert)
mydb.commit()
print("data updated")
break
elif(x==2):
mycursor=mydb.cursor()
mycursor.execute("select*from tdlcommunity")
data=mycursor.fetchall()
for i in data:
print(i)
break
elif(x==3):
userID=int(input("enter your user ID:"))
mydb.commit()
break
elif(x==4):
delete_values=(userid,task)
mycursor.execute(sqldelete,delete_values)
mydb.commit()
break
mycursor.execute(sqldel)
mycursor.execute(sqldel2)
mycursor.execute(sqldel3)
mydb.commit()
print("user deleted")
break
elif(x==6):
sql="select
tdldata.userID,tdldata.task_details,tdldata.task_status,tdldata.due_date,tdlcomm
unity.userID,tdlcommunity.username from tdldata JOIN tdlcommunity on
tdldata.userID=tdlcommunity.userID where
tdlcommunity.userID='"+str(userID)+"'"
mycursor.execute(sql)
r=mycursor.fetchall()
mydb.commit()
print(r)
break
Output:
1.Add user account: