我有这个 PHP 脚本可以在 MAC Snow Leopard 上创建数据库。当我尝试打开创建的 .sqlite 时,我从SQLite 数据库浏览器 2.0 b1(“发生错误:文件不是 SQLite 3 数据库”)和 Firefox SQLite 管理器(“SQLiteManager:打开文件论坛时出错。 sqlite - 文件已加密或损坏异常名称:NS_ERROR_FILE_CORRUPTED 异常消息:组件返回失败代码:0x8052000b (NS_ERROR_FILE_CORRUPTED)[mozIStorageService.openUnsharedDatabase]")。这是我的脚本
<?php
$dbhandle = sqlite_open('forum.sqlite', $error);
if (!$dbhandle) die ($error);
$stm1 = 'CREATE TABLE author' .'(
id INTEGER PRIMARY KEY,
name TEXT,
url TEXT
)';
$ok1 = sqlite_exec($dbhandle, $stm1, $error);
if (!$ok1)
die("Cannot execute query. $error");
echo "Table author created successfully"."\n";
$stm2 = 'CREATE TABLE thread' .'(
id INTEGER PRIMARY KEY,
authorId INTEGER,
title TEXT,
reactions INTEGER,
dislikes INTEGER,
userScore INTEGER,
createdAt DATETIME,
slug TEXT,
postNumber INTEGER,
link TEXT,
likes INTEGER,
message TEXT,
category INTEGER,
score INTEGER,
categoryLink TEXT,
FOREIGN KEY(authorId) REFERENCES author(id)
)';
$ok2 = sqlite_exec($dbhandle, $stm2, $error);
if (!$ok2)
die("Cannot execute query. $error");
echo "Table thread created successfully"."\n";
$stm3 = 'CREATE TABLE commentAuthor' .'(
authorUrl TEXT PRIMARY KEY,
name TEXT
)';
$ok3 = sqlite_exec($dbhandle, $stm3, $error);
if (!$ok3)
die("Cannot execute query. $error");
echo "Table commentAutor created successfully"."\n";
$stm4 = 'CREATE TABLE comment' .'(
id INTEGER PRIMARY KEY,
threadId INTEGER,
forum TEXT,
parent INTEGER,
authorUrl TEXT,
dislikes INTEGER,
rawMEssage TEXT,
createdAt DATETIME,
numReports INTEGER,
likes INTEGER,
message TEXT,
FOREIGN KEY(threadId) REFERENCES thread(id),
FOREIGN KEY(authorUrl) REFERENCES commentAuthor(authorUrl)
)';
$ok4 = sqlite_exec($dbhandle, $stm4, $error);
if (!$ok4)
die("Cannot execute query. $error");
echo "Table comment created successfully"."\n";
sqlite_close($dbhandle);
?>
脚本运行正确,我收到确认表已创建。