PRINTING DATA IN YOUR DATABASE IN PYTHON!!
This is a program in python programming language to display the data in your database. For this I used MySQL database through Xampp Web Server. To work with the database and python, you need to have SQL Database and MySQL connector. If you are using Anaconda, then you can simply install this connector by opening your Anaconda Prompt in Start Menu and then executing the following command line in your Anconda Prompt.
conda install -c anaconda mysql-connector-python
import mysql.connector
db=mysql.connector.connect(host="localhost", user="root", passwd="", database="leoumesh")
mycursor=db.cursor();
mycursor.execute("select * from employee")
tabledata=mycursor.fetchall()
print(tabledata)
for records in tabledata:
print(records)
I already had a database called leoumesh
, and one of the table in this database was employee
.
And you can see that by executing the SQL query in above code, I got all the records of employee
table, which are Emp_Id, Emp_Name, Emp_Contact, Department_Name. Here is the output when I executed the code in Jupyter Python:
If you want to run this code. I have attached the employee table SQL query. Please create a database leoumesh
in your MySQL server and then export query in this file.
This post have been upvoted by the @UpvoteBank service. Want to know more and receive "free" upvotes click here |