'Get Row Count For SQL Dataset in php Class Object

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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source