我正在尝试使用php登录到SQLite数据库。我想将登录页面中输入的“用户名”和“密码”与数据库中存储的用户名和密码进行比较,如果匹配,则重定向到新页面(welcome.php)。我的代码是:
<?php
class MyDB extends SQLite3 {
function __construct() {
$this->open('test.db');
}
}
$db = new MyDB();
if(!$db) {
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully\n";
}
include('config.php');
$username = $_POST['Username'];
$password = $_POST['Password'];
$db = new PDO('sqlite:db/test.db');
$stmt = $db->prepare("SELECT * FROM login where username='$username' && password='$password]'");
$stmt->execute(array($username, $password));
if($stmt->fetchAll()){
?>
<script type="text/javascript">
window.location="welcome.php";
</script>
<?php
}
else {
?>
<script type="text/javascript">
alert("incorrect username or password");
</script>
<?php
}
运行此代码后,我得到一个空白的validate.php页面,其中显示“成功打开数据库”。 apache服务器中的错误日志文件显示以下消息:
[Fri Sep 07 12:13:17.037251 2018] [:error] [pid 16529] [client 192.168.0.110:44534] PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000] [14] unable to open database file in /var/www/html/validate.php:16\nStack trace:\n#0 /var/www/html/validate.php(16): PDO->__construct('sqlite:db/test....')\n#1 {main}\n thrown in /var/www /html/validate.php on line 16, referer: http://192.168.0.110/
谁能告诉我我要去哪里错了?