Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.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 num_rows仅与'store_result()一起使用`_Php_Mysqli - Fatal编程技术网

Php num_rows仅与'store_result()一起使用`

Php num_rows仅与'store_result()一起使用`,php,mysqli,Php,Mysqli,num\u rows仅当我使用mysqli->store\u result()时有效。这意味着它只对缓冲结果有效。有人能解释为什么会这样吗 在下面的代码中,当我使用mysqli->store_result()时,num_rows起作用。否则它会显示0 function retrievearticle($mysqli, $articleid) { echo $articleid; $query="select ArticleText,ArticleTitle from article where

num\u rows
仅当我使用
mysqli->store\u result()
时有效。这意味着它只对缓冲结果有效。有人能解释为什么会这样吗

在下面的代码中,当我使用
mysqli->store_result()
时,
num_rows
起作用。否则它会显示
0

function retrievearticle($mysqli, $articleid)
{
echo $articleid;
$query="select ArticleText,ArticleTitle from article where ArticleId=?";
$stmt=$mysqli->stmt_init();
$stmt->prepare($query);
$stmt->bind_param('i', $articleid);
$stmt->execute();
$stmt->store_result();
echo "here 2";
$stmt->bind_result($ArticleText, $ArticleTitle);
$stmt->fetch();
echo $stmt->num_rows;

} 
:

请注意,对于有时未阅读此功能的重要手册条目的人员:

如果不使用mysqli_stmt_store_result(),并且在执行准备好的语句后立即调用此函数,此函数通常会返回0,因为它无法知道结果集中有多少行,因为结果集尚未保存在内存中

mysqli_stmt_store_result()将结果集保存在内存中,因此在执行语句并保存结果集后,您可以立即使用此函数

如果不保存结果集,但仍要使用此函数,则在使用此函数确定行数之前,必须使用mysqli_stmt_fetch()一次循环一行结果集

一个想法是,如果您想在不存储结果集的情况下确定行数,并且在循环遍历结果集之后,为什么不在每次获取行时在循环中保留一个内部计数器并保存函数调用呢

简言之,只有在保存结果集并希望在循环之前确定行数时,此函数才真正有用,否则您可以像我建议的那样重新使用它


看,别担心。这里是一个d4v1d好了,我会考虑这个答案,如果你可以把它放在那里…谢谢!!请支持新来的人,因为他们是不知道的东西,这就是为什么他们在这里问。我总是收到很差的回复,除了这个….:(我是通过向你解释评论是如何工作的来表示支持的。否则我会标记你的评论。