具体错误,在 PHP 中使用带有 PDO 的 SQLite DB:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 near ",": syntax error' in D:\Projects\2013\Stat collection plugin\stats\htdocs\index.php:8 Stack trace: #0 D:\Projects\2013\Stat collection plugin\stats\htdocs\index.php(8): PDO->exec('CREATE TABLE IF...') #1 {main} thrown in D:\Projects\2013\Stat collection plugin\stats\htdocs\index.php on line 8
编码:
$dbSchema = file_get_contents('../schema.sql');
$PDO = new PDO('sqlite:../stats.db');
$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$PDO->exec($dbSchema);
这是我的架构。当我只有第一个 CREATE TABLE 语句时,错误似乎就在那里,但如果我在以下语句中犯了同样的错误,如果你告诉我,我将不胜感激。提前致谢!
CREATE TABLE IF NOT EXISTS game (
id INTEGER PRIMARY KEY AUTOINCREMENT,
serverName STRING NOT NULL,
map STRING NOT NULL,
winner INTEGER NOT NULL,
gameMode STRING NOT NULL,
controlPoints INTEGER,
setupGate BOOLEAN,
capsRed INTEGER,
capsBlue INTEGER,
winsRed INTEGER,
winsBlue INTEGER,
CONSTRAINT game_winner_teamTypes_id FOREIGN KEY (winner) REFERENCES teamTypes(id)
);
CREATE TABLE IF NOT EXISTS player (
id INTEGER PRIMARY KEY AUTOINCREMENT,
gameId INTEGER NOT NULL,
name STRING NOT NULL,
team INTEGER NOT NULL,
class INTEGER NOT NULL,
queueJump BOOLEAN NOT NULL,
CONSTRAINT player_gameId_game_id FOREIGN KEY (gameId) REFERENCES game(id),
CONSTRAINT player_team_teamTypes_id FOREIGN KEY (team) REFERENCES teamTypes(id),
CONSTRAINT player_class_classTypes_id FOREIGN KEY (class) REFERENCES classTypes(id)
);
CREATE TABLE IF NOT EXISTS stat (
playerId INTEGER NOT NULL,
type INTEGER NOT NULL,
value INTEGER NOT NULL,
CONSTRAINT stat_playerId_player_id FOREIGN KEY (playerId) REFERENCES player(id),
CONSTRAINT stat_type_statTypes_id FOREIGN KEY (type) REFERENCES statTypes(id)
);
CREATE TABLE IF NOT EXISTS teamTypes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name STRING NOT NULL
);
INSERT OR IGNORE INTO teamTypes(id, name) VALUES (0, 'Red'), (1, 'Blue'), (2, 'Spectator');
CREATE TABLE IF NOT EXISTS classTypes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name STRING NOT NULL
);
INSERT OR IGNORE INTO classTypes(id, name) VALUES (0, 'Runner'), (1, 'Rocketman'), (2, 'Rifleman'), (3, 'Detonator'), (4, 'Healer'), (5, 'Constructor'), (6, 'Overweight'), (7, 'Infiltrator'), (8, 'Firebug'), (9, 'Querly');
CREATE TABLE IF NOT EXISTS statTypes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name STRING NOT NULL
);
INSERT OR IGNORE INTO statTypes(id, name) VALUES (0, 'Kills'), (1, 'Deaths'), (2, 'Caps'), (3, 'Assists'), (4, 'Destruction'), (5, 'Stabs'), (6, 'Healing'), (7, 'Defenses'), (8, 'Invulns'), (9, 'Bonus'), (10, 'Dominations'), (11, 'Revenge'), (12, 'Points');