0% found this document useful (0 votes)
4 views1 page

Python With MYSQL Fetching Records From Fetchall

Uploaded by

Mahim Arzoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Python With MYSQL Fetching Records From Fetchall

Uploaded by

Mahim Arzoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python with MYSQL

Fetching records from fetchall()

Import mysql.connector
Con=mysql.connector.connect(host=’localhost’,
User=’root’,
Passwd=’12345’,
Database=’class12’)
Cur=con.cursor()
Cur.execute(“Select * from Employee”)
Data=cur.fetchall()
Cur=con.cursor()

Q 13. How to create a table in database?


Ans: import mysql.connector
Demodb = mysql.connector.connect(host=”localhost”, user-“root”, passwd=”123”,
database=”EDUCATION”)
Democursor demodb.cursor()
Democursor.execute(“CREATE TABLE STUDENT (admn_no int primary key, sname
varchar(30), gender char(1), DOB date, stream varchar(15), marks float”)

Q 14. Write the Python code to insert the data in the table.

Ans: import mvsal.connector


Con=mysql.connector.connect(host=’localhost’,
User=’root’,
Passwd=’12345’,
Database=’class12’)
While True:
No=int(input(“Emp No.:”)) name=input(“Employee Name:”)
Salary=int(input(“Salary:”))
Gender input(“Gender:”)
Dcode=int(input(“DCOde:”))
Query=”Insert into Employee values (%s, ‘%s’, %s, %s, ‘%s’)”%(no, name, salary, 2
dcode, gender)
Cur.execute(query)
Con.commit()
Ch=input(“More? (Y/N)”)
If ch in ‘Nn’:
Break
Print(“Data inserted successfully...”)

You might also like