Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在mysql\u num\u rows()函数上返回的对象_Php_Mysql_Mysqli - Fatal编程技术网

Php 在mysql\u num\u rows()函数上返回的对象

Php 在mysql\u num\u rows()函数上返回的对象,php,mysql,mysqli,Php,Mysql,Mysqli,我正在使用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 = m

我正在使用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;
?>

返回的错误是:警告:mysqli_num_rows()期望参数1是给定对象的mysqli_结果

我以为我在脚本中删除了所有OO PHP实例?我也明白这可能意味着我的查询不正确,所以我在数据库中的MySQL上运行了它,看起来一切正常:

所以我不知道问题出在哪里。我读过很多类似的帖子(也许我遗漏了一篇与我完全相似的帖子),但似乎没有一篇能够解决这个问题。我感谢你的时间和帮助

另外,我理解纯文本密码和使用“password1”的安全问题。我计划在构建时使用更好的安全实践,但我只想先准备好语句

您应该使用

mysqli_stmt_execute
mysqli_stmt_num_rows
您应该使用

mysqli_stmt_execute
mysqli_stmt_num_rows
您应该使用

mysqli_stmt_execute
mysqli_stmt_num_rows
您应该使用

mysqli_stmt_execute
mysqli_stmt_num_rows

除了执行
mysqli_
mysqli_num_行

之外,我还应该补充一点,您帮助我找到了一种更好的语法,可以将输入与数据库进行实际比较,并使其满足我的需要。我使用了
mysqli\u stmt\u init
mysql\u stmt\u prepare
,并且在获得行计数之前还需要使用
mysql\u stmt\u store\u result
。在那之后,我的行数不是零!非常感谢!我还应该补充一点,您的帮助我找到了一种更好的语法,可以将输入与DB进行比较,并使其满足我的需要。我使用了
mysqli\u stmt\u init
mysql\u stmt\u prepare
,并且在获得行计数之前还需要使用
mysql\u stmt\u store\u result
。在那之后,我的行数不是零!非常感谢!我还应该补充一点,您的帮助我找到了一种更好的语法,可以将输入与DB进行比较,并使其满足我的需要。我使用了
mysqli\u stmt\u init
mysql\u stmt\u prepare
,并且在获得行计数之前还需要使用
mysql\u stmt\u store\u result
。在那之后,我的行数不是零!非常感谢!我还应该补充一点,您的帮助我找到了一种更好的语法,可以将输入与DB进行比较,并使其满足我的需要。我使用了
mysqli\u stmt\u init
mysql\u stmt\u prepare
,并且在获得行计数之前还需要使用
mysql\u stmt\u store\u result
。在那之后,我的行数不是零!非常感谢!