php - 即使在调用 store_result 之后 $stmt->num_rows 返回 0

标签 php mysqli prepared-statement

我希望使用 mysqli/准备好的语句来计算下面的查询返回的记录数:

$mysql = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database');
$stmt = $mysql->prepare('SELECT id,vcref,jobtitle,jobtype,jobintro,closingdate FROM jobs WHERE active = 1');
$stmt->execute();
$stmt->store_result;
$stmt->bind_result($id,$vcref,$jobtitle,$jobtype,$jobintro,$closingdate);
$stmt->fetch();
$totalLiveJobs = $stmt->num_rows();

输出始终为0

最佳答案

$stmt->store_result;

应该是:

$stmt->store_result();

关于php - 即使在调用 store_result 之后 $stmt->num_rows 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50123332/

相关文章:

php - 无法连接到数据库 "Fatal error: Call to undefind function mysqli_connect()"

php - SELECT 查询不起作用 MySQL

php - MYSQL查询有问题

php - 从表中获取数据并将其显示在 Bootstrap 表中

javascript - ajax请求symfony后刷新 View 中的数据

java - 如何通过网络发送 FlatBuffers ByteBuffer?

php - mysqli_fetch_array 只显示第一个结果

php - PHP MySQL 函数的 future

mysql - 如何从准备好的语句中获取标量结果?

php - 返回 Laravel 中非空的行