2

这是存储过程

DELIMITER $$
BEGIN

SET @sql = concat(@sql ,'SELECT SQL_CALC_FOUND_ROWS ');
SET @sql = concat(@sql ,';');

prepare stmt from @sql;
execute stmt;
deallocate prepare stmt;

SELECT found_rows();
END

调用存储过程的php。

$mysqli = new mysqli($databaseHostname1, $databaseUsername, $databasePassword);
if(!$mysqli) die('Could not connect: ' . mysql_error());

mysqli_select_db($mysqli, '$db');
if(!$mysqli) die('Could not connect to DB: ' . mysql_error()); 

if ($keywordParam != ''){
$mysqli->query("SET @p_keywordParam = " . "'" . $mysqli->real_escape_string($keywordParam) . "'");
}else{
$mysqli->query("SET @p_keywordParam = NULL");
}

$mysqli->query("SET @p_pageOffset = $pageOffset");

$result = $mysqli->query("CALL getInventory2(@p_keywordParam,@p_pageOffset)");
if(!$result) die("CALL failed: (" . $mysqli->errno . ") " . $mysqli->error);

然后我输出数据

NUMBER OF RESULTS: <? echo <<<<<<< FOUND ROWS HERE >>>>>>>>>   ?>
PAGE 1 of ?


while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
<? echo $row['FIRST_NAME']; ?>
<? echo $row['LAST NAME']; ?>

我需要的是 while 循环之前存储过程中的 found_rows 计数,以便我可以设置分页。

4

1 回答 1

0

运行查询后,运行这个:

选择 FOUND_ROWS() 作为 int_count

于 2013-11-04T17:00:04.250 回答