执行mysqli语句后如何获得行数?

时间:2019-11-15 10:54:29

标签: php session mysqli row

我想在会话变量中存储返回语句的行数,但是我不知道如何。我正在尝试这样做,但是没有用。

$stmt = $con->prepare("SELECT model, type, color FROM item WHERE model LIKE '%$type%'");


$stmt->execute();


$_SESSION['numRows'] = $stmt->num_rows;
echo $_SESSION['numRows'];

$result = $stmt->get_result();

$_SESSION['itemsInfo'] = $result->fetch_all();

1 个答案:

答案 0 :(得分:-1)

我已经解决了问题,它的工作原理如下:

$stmt = $con->prepare("SELECT model, type, color FROM item WHERE model LIKE '%$type%'");


$stmt->execute();

$result = $stmt->get_result();

$_SESSION['itemsInfo'] = $result->fetch_all();
$_SESSION['numRows'] = count($_SESSION['itemsInfo']);
echo $_SESSION['numRows'];