-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlget.py
More file actions
35 lines (28 loc) · 936 Bytes
/
Copy pathsqlget.py
File metadata and controls
35 lines (28 loc) · 936 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
33
import pymysql
from pymysql import Error
class sqlgt():
def getdb(self,query,i=None):
try:
connection = pymysql.connect(
host = "gateway01.ap-southeast-1.prod.aws.tidbcloud.com",
port = 4000,
user = "3LHApunfAprgwZ4.root",
password = "UTR1eix9QCrXfwML",
database = "nifty50",
ssl_verify_cert = True,
ssl_verify_identity = True,
ssl_ca = ""
)
if connection:
cursor=connection.cursor()
cursor.execute(query,i)
ans=cursor.fetchall()
colmn=[i[0] for i in cursor.description]
except Error as e:
print(e)
finally:
if connection:
cursor.close()
connection.close()
print("Connection closed")
return ans,colmn