简体   繁体   中英

SQLite3 query in PHP not querying?

I have a register page on my site which feeds POST data into a PHP file, which then INSERT s it into a database. The problem is, the query:

class DB extends SQLite3{
    function __construct(){
            $this->open('db/userpass.db');
    }
}

$db = new DB();

$db->query("INSERT INTO userpass VALUES($user, $encrypted_pass)");

isn't querying. Picture book is here: http://imgur.com/a/SejKT

You can see my problem in the album. However, I most definitely query 'd.

SELECT performs a query, INSERT doesn't. exec must be used instead.

However, because you are merging data in your command, you better use statements :

$stmt = $db->prepare('INSERT INTO userpass VALUES(:user, :encrypted_pass)');
$stmt->bindValue(':user', $user);
$stmt->bindValue(':encrypted_pass', $encrypted_pass);
if ($stmt->execute()==FALSE) {
    //handle errors here!
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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