MCPcopy Create free account
hub / github.com/PastKing/tgbot-verify / __init__

Method __init__

database_mysql.py:21–36  ·  view source on GitHub ↗

初始化数据库连接

(self)

Source from the content-addressed store, hash-verified

19 """MySQL 数据库管理类"""
20
21 def __init__(self):
22 """初始化数据库连接"""
23 import os
24
25 # 从环境变量读取配置(推荐)或使用默认值
26 self.config = {
27 'host': os.getenv('MYSQL_HOST', 'localhost'),
28 'port': int(os.getenv('MYSQL_PORT', 3306)),
29 'user': os.getenv('MYSQL_USER', 'tgbot_user'),
30 'password': os.getenv('MYSQL_PASSWORD', 'your_password_here'),
31 'database': os.getenv('MYSQL_DATABASE', 'tgbot_verify'),
32 'charset': 'utf8mb4',
33 'autocommit': False,
34 }
35 logger.info(f"MySQL 数据库初始化: {self.config['user']}@{self.config['host']}/{self.config['database']}")
36 self.init_database()
37
38 def get_connection(self):
39 """获取数据库连接"""

Callers

nothing calls this directly

Calls 1

init_databaseMethod · 0.95

Tested by

no test coverage detected