mysql_num_rows() 函数返回的对象
Object returned on mysql_num_rows() function
我正在使用 PHP 过程 mysqli 语法中的准备好的语句编写登录脚本。这是我当前的代码:
<?php
include "/ssincludes/functions.php";
$host = HOST;
$username = USER;
$password = PASSWORD;
$db_name = DATABASE;
$table = TABLEU;
//These includes and constants are fine I checked them all
$con = mysqli_connect($host, $username, $password, $db_name);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$myusername='test';
$mypassword='password1';
$sql="SELECT * FROM $table WHERE user_name=? and password=?";
$result=mysqli_prepare($con, $sql);
mysqli_stmt_bind_param($result, 'ss', $myusername, $mypassword);
mysqli_execute($result);
mysqli_stmt_fetch($result);
$row_cnt = mysqli_num_rows($result);
echo $row_cnt;
?>
返回的错误是:Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given
我以为我删除了脚本中所有 OO PHP 的实例?我也明白这可能意味着我的查询不正确,所以我 运行 它在数据库的 MySQL 上,那里似乎一切正常:
所以我不知道问题出在哪里。我读了很多类似的帖子(也许我遗漏了一个与我的完全相似的帖子)并且 none 似乎可以解决这个问题。感谢您的宝贵时间和帮助。
P.S。我了解纯文本密码和使用 "password1" 的安全问题。我计划在构建它时使用更好的安全实践,但我只想先准备好语句。
你应该使用
mysqli_stmt_execute
mysqli_stmt_num_rows
而不是 mysqli_execute
和 mysqli_num_rows
。
我正在使用 PHP 过程 mysqli 语法中的准备好的语句编写登录脚本。这是我当前的代码:
<?php
include "/ssincludes/functions.php";
$host = HOST;
$username = USER;
$password = PASSWORD;
$db_name = DATABASE;
$table = TABLEU;
//These includes and constants are fine I checked them all
$con = mysqli_connect($host, $username, $password, $db_name);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$myusername='test';
$mypassword='password1';
$sql="SELECT * FROM $table WHERE user_name=? and password=?";
$result=mysqli_prepare($con, $sql);
mysqli_stmt_bind_param($result, 'ss', $myusername, $mypassword);
mysqli_execute($result);
mysqli_stmt_fetch($result);
$row_cnt = mysqli_num_rows($result);
echo $row_cnt;
?>
返回的错误是:Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given
我以为我删除了脚本中所有 OO PHP 的实例?我也明白这可能意味着我的查询不正确,所以我 运行 它在数据库的 MySQL 上,那里似乎一切正常:
所以我不知道问题出在哪里。我读了很多类似的帖子(也许我遗漏了一个与我的完全相似的帖子)并且 none 似乎可以解决这个问题。感谢您的宝贵时间和帮助。
P.S。我了解纯文本密码和使用 "password1" 的安全问题。我计划在构建它时使用更好的安全实践,但我只想先准备好语句。
你应该使用
mysqli_stmt_execute
mysqli_stmt_num_rows
而不是 mysqli_execute
和 mysqli_num_rows
。