mysqli-$ stmt-> num_rows返回0 [英] mysqli - $stmt->num_rows returning 0
本文介绍了mysqli-$ stmt-> num_rows返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望通过mysqli/prepared语句计算以下查询返回的记录数:
i am looking to count the number of records returned by the query below using mysqli / prepared statements:
$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
推荐答案
您正在以OOP风格使用mysql_stmt_num_rows
,因此将其作为函数调用是不正确的.试试:
You're using mysql_stmt_num_rows
in the OOP style, so calling it as a function is incorrect. Try:
$stmt->num_rows;
代替:
$stmt->num_rows();
基本上,您正在尝试获取此值:
Basically, you're trying to get this value:
class mysqli_stmt {
int num_rows
}
也是
$stmt->store_result;
应该是:
$stmt->store_result();
这篇关于mysqli-$ stmt-> num_rows返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文