• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1485
  • Last Modified:

Getting an error when running sqlsrv_has_rows function

I am trying to create an if statement to check if a query came back with rows or not but keep getting the error below.

Warning: sqlsrv_has_rows() expects parameter 1 to be resource, boolean given in

Here is the code that I am using.

$connectionOptions = 

$conn = sqlsrv_connect( $serverName, $connectionOptions)
	 or die("Couldn't connect to SQL Server on $serverName : <br />".print_r(sqlsrv_errors(), true));
$query_check = sqlsrv_query($conn, 'SELECT Name00 FROM System_DATA where Name0 = ?', array($asset));

$num_rows_check = sqlsrv_has_rows($query_check);

if ( $num_rows_check === false ) {
echo "<td>";
} else {
echo "<td class='navigation'>";

Open in new window

  • 2
1 Solution
Dave BaldwinFixer of ProblemsCommented:
You can try sqlsrv_has_rows($conn, $query_check) but I don't know if it will work.  There are several functions in the 'sqlsrv' driver where using the example code just results in an error.
ats2012Author Commented:
Adding Conn is not working. Any other way I can see if any rows are available?
Dave BaldwinFixer of ProblemsCommented:
Sure, sqlsrv_num_rows http://us3.php.net/manual/en/function.sqlsrv-num-rows.php is what I use.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now