num_rows alternative for webspace without MySQLnd

150 views Asked by At

It seems the company I host my webserver with doesn't have MySQLnd installed (or at least not on my server). This means that in php I can not use $stmt->get_result(), which means I can not use $result->num_rows(). I instead have to use $stmt->bind_result() and $stmt->fetch(). Is there an alternative for people in my situation to easily get the number of rows without looping through with fetch()?

Also, same problem with $result->num_rows_affected().

1

There are 1 answers

0
Jans Rautenbach On BEST ANSWER

There doesn't seem to be an alternative. The best I could do was make a method that loops through the rows and returns the count:

function rowCount($stmt) {
    $count = 0;
    while ($stmt->fetch()){
        $count++;
    }
    $stmt->data_seek(0); //reset the stmt to the first row
    return $count;
}

Note this does not solve the rows_affected problem.