更新
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?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);
|
||||
}
|
||||
Reference in New Issue
Block a user