如何在OO PDO中说($ variable!= 0)? [英] How do I say if($variable!=0) in OO PDO?
问题描述
我最近一直在学习OOP和PDO,并认为它真的很棒,但我在尝试将一些代码从程序编程转换为OOP时遇到了问题。
我有一些代码要登录,检查我运行的查询(使用预处理语句)是否为空,查询结果存储在变量中。
Hi,
Ive recently been learning about OOP and PDO and think its really great but Im having a problem trying to convert some code from procedural programming to OOP.
I have some code to log in that checks that the query I run (using prepared statement) isnt empty, and the results of the query is stored in a variable.
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$db = Database::getConnection();
if ($username&&$password)
{
$sqlQuery = "SELECT * FROM users WHERE username=:username";
$loginUser = $db->prepare($sqlQuery);
$loginUser->execute(array(':username' => $username));
if ($loginUser!=0)
{
//Do a while statement and store username, password, activated into variables
} else {
echo "User Doesnt Exist!";
}
}
问题是,我一直收到错误if( $ loginUser!= 0)我认为它是因为在OOP中可能有另一种方法来检查SQL是不是空的。
注意:我得到的错误是: 注意:PDOStatement类的对象无法转换为int ...。
非常感谢您的帮助。
The Problem is, is that I keep getting an error on the line "if ($loginUser!=0)" and I think its because there may be another method in OOP to check the SQL isnt empty.
Note: the Error I get is: "Notice: Object of class PDOStatement could not be converted to int...".
Many thanks for any help.
推荐答案
用户名 =
username =
_REQUEST [' 用户名跨度>];
_REQUEST['username'];
密码 =
password =
这篇关于如何在OO PDO中说($ variable!= 0)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!