Files
2026-07-22 10:18:59 +08:00

33 lines
710 B
PHP

<?php
/**
* 初始化数据库脚本
* 用法: php database/install.php
*/
$sqlFile = __DIR__ . '/schema.sql';
$sql = file_get_contents($sqlFile);
$host = '127.0.0.1';
$user = 'root';
$pass = 'root';
$port = 3306;
try {
$pdo = new PDO("mysql:host={$host};port={$port};charset=utf8mb4", $user, $pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
$statements = array_filter(array_map('trim', explode(';', $sql)));
foreach ($statements as $statement) {
if ($statement !== '') {
$pdo->exec($statement);
}
}
echo "Database installed successfully.\n";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage() . "\n";
exit(1);
}