[英]Getting the result of an SQLite query for PHP
I am trying to obtain the user id from my database, using the query bellow, to insert it somewhere else. 我试图从我的数据库中获取用户ID,使用下面的查询,将其插入其他地方。 I am new to php and sql so I can't really spot what's wrong. 我是php和sql的新手,所以我无法真正发现什么是错的。 The result I get on var_dump() is object (SQLite3Result)#4 (0) { } - I only used this for testing. 我在var_dump()上得到的结果是object(SQLite3Result)#4(0){} - 我只用它进行测试。 I tried using fetchArray() but it still got me nothing. 我尝试使用fetchArray()但它仍然没有给我任何东西。 The database works alright, I used it for other things. 数据库工作正常,我用它做其他事情。
require 'database.php';
$db = new Database();
$email = $_POST['member'];
$list = $db->prepare('SELECT userid FROM users WHERE (email = :email)');
$list->bindValue(':email', $email, SQLITE3_TEXT);
$q = $list->execute();
var_dump($q);
Thanks for any help! 谢谢你的帮助!
Here is what you can do: 这是你可以做的:
<?php
class UserDB extends SQLite3
{
function __construct()
{
$this->open('test.db');
}
}
$db = new UserDB();
$stmt = $db->prepare('SELECT * FROM users where email = :email');
$stmt->bindValue(':email', 'user1@example.com', SQLITE3_TEXT);
$result = $stmt->execute();
var_dump($result->fetchArray());
Then you can update the bindValue method call with the email variable. 然后,您可以使用email变量更新bindValue方法调用。
For the sqlite3 db I created it using the following commands: 对于sqlite3 db,我使用以下命令创建它:
$ sqlite3 test.db
CREATE TABLE USERS (
ID INT PRIMARY KEY NOT NULL,
EMAIL TEXT NOT NULL
);
INSERT INTO USERS VALUES(1, 'user1@example.com');
.quit
Then you can use that with my code. 然后你可以用我的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.