库MySQLi - $ stmt-> NUM_ROWS返回0(mysqli - $stmt

2019-08-21 19:32发布

我期待计数由下面使用的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 consistantly

Answer 1:

您正在使用mysql_stmt_num_rows在OOP风格,所以称它作为函数不正确。 尝试:

$stmt->num_rows;

代替:

$stmt->num_rows();

基本上,你正在试图获得该值:

class mysqli_stmt { 

   int num_rows

}

也,

$stmt->store_result;

应该:

$stmt->store_result();


文章来源: mysqli - $stmt->num_rows returning 0