You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.0 KiB
45 lines
1.0 KiB
import pymysql
|
|
|
|
|
|
# 建立数据库连接
|
|
def connect_To_database():
|
|
try:
|
|
conn = pymysql.connect(
|
|
host='localhost',
|
|
user='root',
|
|
password='cyh0110',
|
|
db='ec',
|
|
charset='utf8'
|
|
)
|
|
# print('连接成功')
|
|
return conn
|
|
except pymysql.Error as e:
|
|
print('连接失败!', e)
|
|
|
|
|
|
def insert_data(conn, insert_query, list_code):
|
|
# 创建游标
|
|
cursor = conn.cursor()
|
|
# # 创建表
|
|
# new_tree_code = '''
|
|
# create table if not exists fractal(
|
|
# id int AUTO_INCREMENT primary key,
|
|
# name TEXT,
|
|
# fractal_e TEXT,
|
|
# params_initial TEXT,
|
|
# str_params TEXT,
|
|
# pattern TEXT,
|
|
# tree TEXT,
|
|
# update_tree TEXT)
|
|
# '''
|
|
# cursor.execute(new_tree_code)
|
|
|
|
# 执行插入语句
|
|
cursor.execute(insert_query, list_code)
|
|
|
|
conn.commit()
|
|
# 关闭数据库
|
|
conn.close()
|
|
# 关闭游标
|
|
cursor.close()
|