我的 PHP 脚本中有以下 SQLite QUERY:
try
{
//open the database
$db = new PDO('sqlite:users.sqlite');
//create the database or view existing
$db->exec("CREATE TABLE USERS (Id INTEGER PRIMARY KEY, Type TEXT, Name TEXT, Password TEXT)");
//select records with username and password match
$existUser = $db->query("SELECT COUNT(*) FROM Users WHERE Name='" . $incomingusername . "' and Password ='" . $incomingpassword . "'");
//check that either the result string isn't empty or somehow count rows
$result = sqlite_num_rows($existUser);
print $result;
echo "Done output from SQL<BR>";
// close the database connection
$db = NULL;
}
catch(PDOException $e)
{
print 'Exception : '.$e->getMessage();
}
我从这里得到一个错误:致命错误:调用未定义的函数 sqlite_num_rows()
所以我做了一些搜索,结果发现语言规范是谎言,这种方法不存在。我只需要测试我的 sqlite 数据库是否包含用户名和密码。我也试过 SELECT COUNT(*) FROM Users WHERE Name='Jeff' and Password ='Monhty'; 但这不会返回任何我可以使用的东西,我不明白返回结果的类型。当我在控制台中针对数据库运行此 SELECT COUNT 时,我得到了一个完全正确的结果。
请有人指出我可以使用的 SQL 字符串,让我在我的 PHP 脚本中将其结果视为布尔值?非常感谢。
Ninjaedit - ->numRows(); 也不起作用。也不认可。