-1

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.

  • You said it yourself your are executing update query which does not return any rows – KKK Apr 14 '14 at 12:56

1 Answers1

2

"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);
h2ooooooo
  • 37,963
  • 8
  • 65
  • 101
  • Thanks h20000000, i have just tried affected rows but i am getting the same error, could it be that i am passing the return value to the _result property rather than passing the $query directly to mysqli_num_rows(). Thanks again. – user2784408 Apr 14 '14 at 13:10
  • @user2784408 As you can see it's **not** `mysqli_affected_rows($this->_result)`. You have to use the link - not the result. – h2ooooooo Apr 14 '14 at 13:19
  • A Lannister always pays his debts. – user2784408 Apr 14 '14 at 13:29