mysqli-$stmt->num\u行返回0

1zmg4dgp  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(381)

我希望使用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

rhfm7lfc

rhfm7lfc1#

你用的是 mysql_stmt_num_rows 在oop风格中,将其作为函数调用是不正确的。尝试:

$stmt->num_rows;

而不是:

$stmt->num_rows();

基本上,你想得到这个值:

class mysqli_stmt { 

   int num_rows

}

也,

$stmt->store_result;

应该是:

$stmt->store_result();

相关问题