Untitled
unknown
python
2 years ago
713 B
11
Indexable
import mariadb
import sys
import dbconfig
try:
conn = mariadb.connect(
user=dbconfig.user,
password=dbconfig.password,
host=dbconfig.host,
port=dbconfig.port,
)
except mariadb.Error as e:
print(f'Error connecting to MariaDB Platform: {e}')
sys.exit(1)
cursor = conn.cursor()
try:
cursor.execute('CREATE DATABASE IF NOT EXISTS test_db')
cursor.execute('USE test_db')
cursor.execute('CREATE TABLE IF NOT EXISTS test_table (name VARCHAR(40), value INT)')
params = [
('test1', 1),
('test2', 2),
('test3', 3),
]
cursor.executemany('INSERT INTO test_table (name, value) VALUES (?, ?)', params)
conn.commit()
except mariadb.Error as e:
print(f'Error: {e}')Editor is loading...
Leave a Comment