首页> PHP的> MySQli行计数总是返回0? [英] php - MySQli row count always returning 0?
问题描述
rowLogin
总是返回0
?但是当我在sql上运行查询时,我得到正确的结果!我看过很多解决方案,但实际上没有一个起作用.
rowLogin
is always returning 0
? but when i run the query on sql i get the correct outcome! I've had a look at loads of solutions but literally none are working.
$queryLogin =("SELECT count(*) as count FROM `tblUser` WHERE `username` = '$username' and `password` ='$password'");
$resultLogin = $mysqli->query($queryLogin);
$rowLogin = $resultLogin->fetch_assoc();
echo $rowLogin['count']." rows in table tblUser.";
推荐答案
您的代码不是很好...
Your code is not very good...
您确实需要使用带有用户名/通过检查的MYSQLi准备的语句esp ...
You really need to be using MYSQLi prepared statements esp with username / pass checks...
$mysqli = new mysqli(...);
$query = "SELECT count(*) as count FROM `tblUser` WHERE `username`=? and `password`=?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('ss',$username,$password);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows){
$row = $result->fetch_assoc();
echo $row['count'] . " rows in table tblUser.";
}
我了解您可能只是在获取一些信息,但这是采取此方法的最佳途径.不要继续前进.
I understand you are potentially looking into just getting some information, but this is the best route to take so move this way. Do not continue in your path.
您的查询很可能失败,因为您的实际查询中包含( )
.因此,如果您要使用它,只需在与$queryLogin
相同的行中删除( )
.
It is very likely that your query failed because you have ( )
around your actually query. So if you want to use that just get rid of the ( )
on the line with $queryLogin
.
这篇关于首页> PHP的> MySQli行计数总是返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!