【发布时间】:2011-12-01 03:30:59
【问题描述】:
我正在尝试使用 php 的 sqlite。在服务器上,当我执行命令 sqlite3 时,它会显示版本和帮助选项,建议在那里安装 sqlite。我的文件夹结构是这样的:/username/public_html/
现在我使用 /username 的 sqlite3 命令创建了一个名为“chatuser.db”的数据库,其中包含一个表“用户”和两列“用户名”和“密码”
然后,我使用 WinSCP 将 db 复制到我的 windows 文件夹,然后将其复制回此处的服务器:/username/public_html/(我知道将 db 文件保存在 public_html 中不是一个好主意,但我只是在尝试一个示例) .现在我有以下 php 文件:
添加.php:
<?php
$password = $_POST['password'];
$username = $_POST['username'];
$name_es = sqlite_escape_string($username);
$password_es = sqlite_escape_string($password);
if (!empty($username)) {
$dbhandle = sqlite_open('chatuser.db', 0666, $error);
if (!$dbhandle) die ($error);
$stm = "INSERT INTO Users(Username, Password) VALUES('$name_es', '$password_es')";
$ok = sqlite_exec($dbhandle, $stm, $error);
if (!$ok) die("Error: $error");
else echo "Success";
}
?>
index.html:
<html>
<head>
<title>Login Trial</title>
</head>
<body style="font-size:12;font-family:verdana">
<form action="add.php" method="post">
<p>
Name: <input type="text" name="username"><br>
Password: <input type="text" name="password"><br><br>
</p>
<p>
<input type="submit">
</p>
</form>
</body>
</html>
单击提交按钮时,它会加载 add.php,但不会显示成功消息或任何错误消息。我不知道为什么。作为补充说明,我也完成了 chatuser.db 的 chmod 777。这是我对 sqlite 的第一次介绍,任何帮助都会很棒。谢谢
[已解决] 发现问题,版本不匹配。 sqlite_open 将不起作用。此解决方案的替代方案: Error: file is encrypted or is not a database
【问题讨论】: