Search code examples
phpmysqliprepared-statement

$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


Solution

  • $stmt->store_result;
    

    Should be:

    $stmt->store_result();