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 = 
	array(
		"Database"=>$SCCM_Database, 
		"UID"=>$SCCM_Username, 
		"PWD"=>$SCCM_Password);


$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

ats2012Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
0
ats2012Author Commented:
Adding Conn is not working. Any other way I can see if any rows are available?
0
Dave BaldwinFixer of ProblemsCommented:
Sure, sqlsrv_num_rows http://us3.php.net/manual/en/function.sqlsrv-num-rows.php is what I use.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.