我希望使用mysqli / prepared语句计算下面查询返回的记录数:
$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
答案 0 :(得分:9)
您在OOP样式中使用mysql_stmt_num_rows
,因此将其作为函数调用是不正确的。尝试:
$stmt->num_rows;
而不是:
$stmt->num_rows();
基本上,你正试图获得这个值:
class mysqli_stmt {
int num_rows
}
另外,
$stmt->store_result;
应该是:
$stmt->store_result();