Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$stmt->num_rows returning 0 even after calling store_result

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();

The output is consistently 0

like image 834
Aaron Bentley Avatar asked Jan 23 '23 02:01

Aaron Bentley


1 Answers

$stmt->store_result;

Should be:

$stmt->store_result();
like image 68
karim79 Avatar answered Feb 14 '23 09:02

karim79