-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest.py
More file actions
32 lines (31 loc) · 993 Bytes
/
test.py
File metadata and controls
32 lines (31 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import mysql.connector
from mysql.connector import Error
try:
mySQLconnection = mysql.connector.connect(host='localhost',
database='test',
user='shiv',
password='tarun')
sql_select_Query = "select * from vision"
cursor = mySQLconnection .cursor()
cursor.execute(sql_select_Query)
records = cursor.fetchall()
print("Total number of rows in python_developers is - ", cursor.rowcount)
f= open("vision.md","w")
heads=cursor.description
for row in records:
i=0
for head in heads:
h="#"+str(head[0])+"\n"
r=str(row[i])+"\n"
f.write(h)
f.write(r)
i=i+1
cursor.close()
except Error as e :
print ("Error while connecting to MySQL", e)
finally:
#closing database connection.
if(mySQLconnection .is_connected()):
mySQLconnection.close()
f.close()
print("MySQL connection is closed")