我有这个PHP脚本在MAC Snow Leopard上创建数据库。当我尝试打开创建的.sqlite时,我收到来自 SQLite数据库浏览器2.0 b1 (“发生错误:文件不是SQLite 3数据库”)和Firefox SQLite Manager的错误消息(“SQLiteManager:打开文件forum.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);
?>
脚本运行正常,我收到表格的确认。
答案 0 :(得分:2)
这些sqlite_
*函数创建SQLite 2数据库。
对于SQLite 3数据库,请使用PDO。
答案 1 :(得分:0)
或者代替PDO,你也可以使用它:http://php.net/sqlite3
(但我也更喜欢PDO)