简体   繁体   English

SQLite3 无法获取列

[英]SQLite3 cant fetch columns

I wrote my code as simple as possible to make a simple login, because its my first time working with SQLite3 databases.我编写了尽可能简单的代码来进行简单的登录,因为这是我第一次使用 SQLite3 数据库。

Here is my code:这是我的代码:

<?php
$db  = new SQLite3("FirstDatabase.db");

if (isset($_POST['login'])) {
    $username = $_POST['user'];
    $password = $_POST['pass'];

    $query = $db->prepare("SELECT COUNT(`id`) FROM data WHERE `username` = '$username' AND `password` = '$password'");
    $query->execute();

    $count = $query->fetchColumn();

    if($count = 1){
        echo "Welcome $username!";
    } else {
        echo "Wrong credentials";
    }
}

?>

I'm really confused why this is not working.. I updated all the extensions etc. I know this is vulnerable to pretty much every type of attack, but I'm just trying to figure out the SQLite3 database connection.我真的很困惑为什么这不起作用..我更新了所有扩展等。我知道这很容易受到几乎所有类型的攻击,但我只是想弄清楚 SQLite3 数据库连接。

Thanks!谢谢! :) :)

This is the Error I get btw:这是我得到的错误:

Fatal error: Uncaught Error: Call to undefined method SQLite3Stmt::fetchColumn() in C:\\XAMPP\\htdocs\\PHP-Login\\index.php:41 Stack trace: #0 {main} thrown in C:\\XAMPP\\htdocs\\PHP-Login\\index.php on line 41致命错误:未捕获错误:调用 C:\\XAMPP\\htdocs\\PHP-Login\\index.php:41 中未定义的方法 SQLite3Stmt::fetchColumn() 堆栈跟踪:#0 {main} throw in C:\\XAMPP\\htdocs\\第 41 行的 PHP-Login\\index.php

The SQL is vulnerable to SQL injection which could be devastating to your database and your system and your health. SQL 容易受到 SQL 注入的攻击,这可能对您的数据库、系统和健康造成破坏。 First and foremost you should change the select to a parametrized query.首先,您应该将选择更改为参数化查询。

There are very good examples in the doc for using a parametrized query and binding the values, not to mention a ton of resource on this site.文档中有非常好的示例用于使用参数化查询和绑定值,更不用说本站点上的大量资源了。

The error is telling you that that there is not method fetchColumn() for a SQLite3Stmt object.该错误告诉您没有SQLite3Stmt对象的fetchColumn()方法。 The PHP: SQLite3Stmt doc confirms that. PHP: SQLite3Stmt 文档证实了这一点。 It is a method on the PDO database extension.它是 PDO 数据库扩展上的一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM