Mysqli - $ stmt-> num_rows returning 0

I expect to count the number of records returned by the query below using the mysqli / ready commands:

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

Conclusion consistent 0

+3
source share
1 answer

You use mysql_stmt_num_rowsOOP style, so its purpose as a function is incorrect. Try:

$stmt->num_rows;

instead:

$stmt->num_rows();

Basically, you are trying to get this value:

class mysqli_stmt { 

   int num_rows

}

Moreover,

$stmt->store_result;

Must be:

$stmt->store_result();
+8
source

Source: https://habr.com/ru/post/1720569/


All Articles