CodeIgniter Forums
num_rows() not working with sqlsrv driver and MSSQL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: num_rows() not working with sqlsrv driver and MSSQL (/showthread.php?tid=71299)



num_rows() not working with sqlsrv driver and MSSQL - sebastianbo - 07-30-2018

I'm getting the following error on a simple query that's supposed to return a number of rows:
Quote:Type: Error
Message: Call to a member function num_rows() on boolean
Filename: /var/www/dev/docroot/project/system/database/DB_query_builder.php
Line Number: 1428

I'm using Codeigniter 3.1.9. I recently started using PHP7.2 and also sqlsrv driver to connect to a MSSQL database.
In some other post, someone mentioned that scrollable should be set to an option different than SQLSRV_CURSOR_FORWARD so I dump the value of $this->scrollable in sqlsrv_driver.php and found out that its value is buffered

Code:
/**
    * Execute the query
    *
    * @param   string  $sql    an SQL query
    * @return  resource
    */
   protected function _execute($sql)
   {
       echo $this->scrollable; die();
       return ($this->scrollable === FALSE OR $this->is_write_type($sql))
           ? sqlsrv_query($this->conn_id, $sql)
           : sqlsrv_query($this->conn_id, $sql, NULL, array('Scrollable' => $this->scrollable));
   }

Not quite sure why it's failing. Any other queries that don't include num_rows() are fine so far. Thanks.



RE: num_rows() not working with sqlsrv driver and MSSQL - InsiteFX - 07-31-2018

num of rows is mostly for MySQL

Documentation states this that different database engines use a different num of rows.

You can use php count method to get the number of rows.


RE: num_rows() not working with sqlsrv driver and MSSQL - sneakyimp - 09-12-2018

That error looks like you are trying to call the num_rows method on some variable that is a boolean value and not an object. I.e., you'll get the same exact error if you do this:
Code:
$v = TRUE;
$v->num_rows();
This frequently happens when people neglect to check if their query succeeded before trying to use the results of the query.