当我在 phpMyAdmin 中进行 SQL 搜索(用变量代替实际值)时,它返回正确的行号,但是当使用 PHP 返回这个值时,无论如何它总是返回 1.提前致谢.
When I do a SQL search in phpMyAdmin (substituting the variable for the actual value) it returns the correct row number but when using PHP to return this value it always returns 1 no matter what. Thanks in advance.
function user_exists($username) {
$link = mysqli_connect('localhost','root','','test');
$username = sanitize($username);
$query = mysqli_query($link, "SELECT COUNT(`user_id`) FROM `new_base` WHERE `username`='$username'");
$row_cnt = mysqli_num_rows($query);
echo $row_cnt;
mysqli_free_result($query);
mysqli_close($link);
}
当你使用 COUNT(*)
你即使计数为零也总是返回一行.
你要么:
count(*)
然后使用mysqli_num_rows()
或count(*)
count(*)
and then use mysqli_num_rows()
orcount(*)
.
$row = mysqli_fetch_assoc($query);
echo $row['COUNT(`user_id`)'];
这篇关于mysqli_num_rows 返回 1 无论如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!