Issue
I am passing $query"UPDATE...", which has no errors, to a query method. I have checked other posts but they all point to the query which does not appear to be my problem.
public function query($sql) {
$this->_result = mysqli_query($this->_link, $sql);
$this->_numRows = mysqli_num_rows($this->_result);
}
$db->numRows();
I am receiving the error 'mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in...', like i said there is nothing wrong with the query, _numRows is returning the correct value but the numRows() method which returns _numRows, is returning the error. Any ideas would be much appreciated. Thanks.
Solution
"I am passing an UPDATE query.."
Read the documentation for mysqli::query:
Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.
Hence no rows are returned (which is what mysqli_num_rows does). You're most likely looking for mysqli::$affected_rows instead (that shows how many rows were affected - not how many rows were returned):
$this->_numRows = $this->_link->affected_rows;
or
$this->_numRows = mysqli_affected_rows($this->_link);
Answered By - h2ooooooo Answer Checked By - Senaida (sql.easybugfix Volunteer)
Post a Comment
Post a Comment