0

I've tried to find a good source of info for this but struggling.

I have a php class which gets a dataset from an SQL (Not MySQL) database.

I need to obtain a dataset row number.

The following is within a class method function:

$this->mat_sql_query = "SELECT * FROM WHATEVER";
$this->mat_sql_data = sqlsrv_query($this->sql_connection, $this->mat_sql_query);

$this->mat_sql_count= $this->mat_sql_data->num_rows;
        
if($this->mat_sql_count>0){
  echo "Got Data";
} else {
  echo "No data";
}

I've tried variations of sql_num_rows(), count() and num_rows but all fail for various reasons.

What is the method and syntax needed here please?

Richard Owens
  • 155
  • 16
  • I've tried "$this->mat_sql_count = count($this->mat_sql_data);" but get "Warning: count(): Parameter must be an array or an object that implements Countable in......" – Richard Owens Feb 16 '22 at 12:17
  • I've now also tried "$this->mat_sql_count = sqlsrv_num_rows($this->mat_sql_data);" but it doesn't return a value. – Richard Owens Feb 16 '22 at 12:25
  • Just found the answer at https://stackoverflow.com/questions/23741534/sqlsrv-num-rows-not-returning-any-value – Richard Owens Feb 16 '22 at 12:28

0 Answers0