[英]Query and Fetch Comparison SQLite
I'm just creating a simple login script to check the username/password, if there's a match with the database then it'll login. 我只是创建一个简单的登录脚本来检查用户名/密码,如果与数据库匹配,则它将登录。 I think I have most of it, it opens up the database, grabs username/pw from the login.
我想我拥有大部分信息,它可以打开数据库,并从登录名中获取用户名/密码。 I think I set up my query right also that it grabs the username and pw.
我想我也正确设置了查询,以获取用户名和密码。 How would I go about comparing it?
我将如何进行比较? I've been stuck on this for quite a while.
我已经坚持了很长时间。 My fetch isn't working correctly also, it gives me an error.
我的提取操作也不正常,这给了我一个错误。 I'm very new to SQLite/Databases so this may seem very bad code but I'm trying my best.
我是SQLite / Databases的新手,所以这似乎是非常糟糕的代码,但我正在尽力而为。
<?php
//opens database
class MyDB extends SQLite3
{
function __construct()
{
$this->open('UserAccounts.db');
}
}
$db = new MyDB();
//username and pw from index.html
$user = $_REQUEST['myusername'] ;
$pw = $_REQUEST['mypassword'] ;
//if there is a database, it opens.
if(!$db){
echo $db->lastErrorMsg();
} else {
//Test to see if things are working correctly.
echo "Opened database successfully\n";
echo "$user";
echo "$pw";
}
$result = $db->query("SELECT * FROM login WHERE user = '$user' AND password = '$pw'");
if ($result->fetchColumn() == $user) {
$_SESSION['loggedin'] = true;
echo "Success";
};
if(!$_SESSION['loggedin']){
echo "Didn't Work";
exit;
};
Probably looks like this: 可能看起来像这样:
$fromDB = $result->fetchArray();
if ($fromDB['user'] == $user) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.