-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
39 lines (27 loc) · 945 Bytes
/
db.py
File metadata and controls
39 lines (27 loc) · 945 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
34
35
36
37
38
39
import mysql.connector as mariadb
class database:
def db_connect(self):
mariadb_cnx = mariadb.connect(user='db_user', password='db_password', database='db_name')
return mariadb_cnx
print "connected"
def db_table(self):
create_string = (
"CREATE TABLE `Jsondata` ("
" `artistId` varchar(14) ,"
") ENGINE=MariaDB")
insert_string = ("INSERT INTO Jsondata "
"(kind)"
"VALUES (%(VALUE)s)")
try:
db_cnx = database().db_connect()
cursor = db_cnx.cursor()
print "db connected"
cursor.execute(create_string)
cursor.execute(insert_string)
except mariadb.Error as error:
print("Error: {}".format(error))
else:
print("Table created")
cursor.close()
db_cnx.close()
database().db_table()