- Complete expansion guide for 2/4/6 node scenarios - Quick join scripts for worker and master nodes - Health check and diagnostic scripts - Quick reference card for common operations
23 lines
751 B
PHP
23 lines
751 B
PHP
<?php
|
|
require_once 'config.php';
|
|
|
|
class Database {
|
|
private static ?PDO $instance = null;
|
|
|
|
public static function getConnection(): PDO {
|
|
if (self::$instance === null) {
|
|
try {
|
|
$dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=" . DB_CHARSET;
|
|
self::$instance = new PDO($dsn, DB_USER, DB_PASS, [
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
PDO::ATTR_EMULATE_PREPARES => false,
|
|
]);
|
|
} catch (PDOException $e) {
|
|
die("数据库连接失败: " . $e->getMessage());
|
|
}
|
|
}
|
|
return self::$instance;
|
|
}
|
|
}
|