Python

0

Python Project – Sales Data Analytics

Program 1 import mysql.connector from tabulate import tabulate # Database connection def connect_db(): return mysql.connector.connect( host=”localhost”, user=”root”, password=”root”, database=”sales_db” ) # 1. View Total Revenue def view_total_revenue(conn): cursor = conn.cursor() query = “”” SELECT...

0

Python PDBC with OOPs Part – 3

Program 1 # PDBC with OOPS import MySQLdb class EmployeeDatabase: # Connection def __init__(self): self.con=MySQLdb.connect(host=’localhost’,user=’root’,password=’root’,database=’college’) #print(“Connection success”) # Insert record def insertdata(self,name,dept,salary,gender,city): try: sql=”insert into employee values(%d, ‘%s’,’%s’,%d,’%s’,’%s’)” self.cur=self.con.cursor() value=(self.maxid,name,dept,salary,gender,city) n=self.cur.execute(sql %value) self.con.commit() print(“Record...

0

How to Execute Parameterized Query in Python PDBC

Program 1 # Program for PDBC import MySQLdb try: con=MySQLdb.connect(host=’localhost’,user=’root’,password=’root’,database=’DataFlair’) print(“Data Base connected”) eno=int(input(“Enter Employee No:”)) name=input(“Enter Employee Name:”) mobile=int(input(“Enter Mobile No:”)) age=int(input(“Enter Employee age:”)) sql=”insert into employee values(%d,’%s’,%d,%d)” values=(eno,name,mobile,age) cur=con.cursor() n=cur.execute() con.commit() print(“Record...

0

DELETE and UPDATE Command in Python PDBC

Program 1 # Program for PDBC Delete Data by id import MySQLdb try: con=MySQLdb.connect(host=’localhost’,user=’root’,password=’root’,database=’DataFlair’) print(“Data Base connected”) empid=int(input(“Enter employee id for delete: “)) sql=”delete from employee where eid={}” sql=sql.format(empid) cur=con.cursor() n=0 n=cur.execute(sql) con.commit() if(n==0):...

0

How to Fetch One Record From Database in Python

Program 1 # Program to search one record (based on PK) import MySQLdb try: con=MySQLdb.connect(host=’localhost’,user=’root’,password=’root’,database=’college’) #print(“Data base connected”) empid=int(input(“Enter employee id for search: “)) sql=”select * from employee where eid={}” sql=sql.format(empid) cur=con.cursor() cur.execute(sql) result=cur.fetchone()...

0

How to Fetch All Record From Database

Program 1 # Program for Select data(search) import MySQLdb try: con=MySQLdb.connect(host=’localhost’,user=’root’,password=’root’,database=’DataFlair’) #print(“Data Base connected”) sql=”select * from employee” cur=con.cursor() cur.execute(sql) result=cur.fetchall() print(“——————————————“) print(“Emp Id\t Emp Name\t Mobile\t Age”) print(“——————————————“) for row in result: print(“%d\t...

0

Python Project – Patient Record System

SQL Queries CREATE DATABASE hospital_db; USE hospital_db; CREATE TABLE patients ( patient_id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), age INT, gender VARCHAR(10), contact VARCHAR(15) ); CREATE TABLE visits ( visit_id INT AUTO_INCREMENT PRIMARY KEY,...

0

Python Project – Restaurant Billing System

SQL Queries CREATE DATABASE restaurant_db; USE restaurant_db; CREATE TABLE customers ( customer_id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), contact VARCHAR(15) ); CREATE TABLE menu_items ( item_id INT AUTO_INCREMENT PRIMARY KEY, item_name VARCHAR(100), price DECIMAL(10,2)...